Skip to content

fix(security): patch 4 critical vulnerabilities#246

Merged
yaojin3616 merged 4 commits intodataelement:mainfrom
Frankshen923:fix/security-audit
Apr 13, 2026
Merged

fix(security): patch 4 critical vulnerabilities#246
yaojin3616 merged 4 commits intodataelement:mainfrom
Frankshen923:fix/security-audit

Conversation

@Frankshen923
Copy link
Copy Markdown
Contributor

Summary

Security audit identified 4 critical vulnerabilities. This PR patches all of them with minimal, focused changes (7 files, +63/-23 lines).

1. Unauthenticated API Key Generation (gateway.py)

POST /gateway/agents/{agent_id}/api-key had no authentication. Added Depends(get_current_user) + creator/admin role check using existing check_agent_access().

2. API Keys Stored in Plaintext (enterprise.py, agents.py, task_executor.py)

  • LLM API keys: Now encrypted using existing encrypt_data()/decrypt_data() (AES-256-CBC)
  • Agent API keys: Now hashed with SHA-256 (consistent with the create flow in gateway.py)

3. Default JWT Secrets Accepted in Production (main.py)

Added startup check: application refuses to boot if SECRET_KEY or JWT_SECRET_KEY contains "change-me" unless DEBUG=true.

4. Multi-Tenant Isolation Gaps (permissions.py, plaza.py, task_executor.py)

  • check_agent_access(): Added tenant_id validation for non-admin users
  • Plaza API: list_posts and plaza_stats now require authentication and enforce tenant from JWT
  • LLM model lookup: Added tenant_id filter to prevent cross-tenant model access

Test Plan

  • POST /gateway/agents/{id}/api-key returns 401 without auth token
  • LLM API keys encrypted in database (api_key_encrypted column is ciphertext)
  • App refuses to start with default SECRET_KEY in non-DEBUG mode
  • Cross-tenant agent access returns 403
  • GET /plaza/posts without auth returns 401; with auth returns only own tenant's posts
  • LLM model lookup respects tenant boundaries

Notes

  • All fixes use existing infrastructure (encrypt_data, check_agent_access, get_current_user) — no new dependencies
  • Backward compatible: existing encrypted keys will work after migration (plaintext keys need re-encryption)
  • Discovered during enterprise deployment evaluation

🤖 Generated with Claude Code

Security audit identified 4 critical issues. All patched with minimal changes.

1. Unauthenticated API key generation (gateway.py)
   - Added Depends(get_current_user) + creator/admin role check
   - Used existing check_agent_access() for consistent auth

2. API keys stored in plaintext (enterprise.py, agents.py, task_executor.py)
   - LLM API keys: encrypt with existing encrypt_data()/decrypt_data() (AES-256)
   - Agent API keys: hash with SHA-256 (consistent with create flow)

3. Default JWT secrets accepted in production (main.py)
   - Startup check: refuse to boot with "change-me" secrets unless DEBUG=true

4. Multi-tenant isolation gaps (permissions.py, plaza.py, task_executor.py)
   - check_agent_access(): validate tenant_id match for non-admin users
   - Plaza API: enforce tenant from JWT, not optional query parameter
   - LLM model lookup: filter by agent's tenant_id
@wisdomqin
Copy link
Copy Markdown
Contributor

@yaojin3616

yaojin and others added 3 commits April 13, 2026 10:40
…up dead imports

- Add auth + tenant isolation to create_post, get_post, create_comment, like_post
- Add tenant check to delete_post
- Fix except (ValueError, Exception) → except ValueError in llm_utils.py and main.py
- Re-add LLM API key migration at startup with correct exception handling
- Remove unused imports: decrypt_data (task_executor), get_current_user/check_agent_access/is_agent_creator (gateway)
- Remove dead imports from gateway.py: secrets, BackgroundTasks, update
@yaojin3616 yaojin3616 merged commit 1ecd642 into dataelement:main Apr 13, 2026
lijiajun1997 added a commit to lijiajun1997/Clawith that referenced this pull request Apr 14, 2026
Sync with upstream:
- A2A async communication improvements
- Multiple new search engine tools (exa, tavily, google, bing, duckduckgo)
- Security patches (dataelement#246)
- Light theme CSS variables
- Agent-to-agent message improvements
- Message history loading (latest 500)

Conflict resolutions:
- agent_tools.py: keep zhipu_search + _convert_markdown (audit-firm) + all new search tools (dataelement)
- websocket.py: keep fallback_model + on_notify + max_tool_rounds_override
- config.py: keep both LLM_RETRY_MAX and EXA_API_KEY
- tool_seeder.py: keep zhipu + exa engines, is_default=True
- index.css: keep [data-theme="light"] block + audit-firm login-field styles
nap-liu pushed a commit to nap-liu/Clawith that referenced this pull request Apr 16, 2026
* fix(security): patch 4 critical vulnerabilities

Security audit identified 4 critical issues. All patched with minimal changes.

1. Unauthenticated API key generation (gateway.py)
   - Added Depends(get_current_user) + creator/admin role check
   - Used existing check_agent_access() for consistent auth

2. API keys stored in plaintext (enterprise.py, agents.py, task_executor.py)
   - LLM API keys: encrypt with existing encrypt_data()/decrypt_data() (AES-256)
   - Agent API keys: hash with SHA-256 (consistent with create flow)

3. Default JWT secrets accepted in production (main.py)
   - Startup check: refuse to boot with "change-me" secrets unless DEBUG=true

4. Multi-tenant isolation gaps (permissions.py, plaza.py, task_executor.py)
   - check_agent_access(): validate tenant_id match for non-admin users
   - Plaza API: enforce tenant from JWT, not optional query parameter
   - LLM model lookup: filter by agent's tenant_id

* fix(security): complete plaza auth, tighten exception handling, cleanup dead imports

- Add auth + tenant isolation to create_post, get_post, create_comment, like_post
- Add tenant check to delete_post
- Fix except (ValueError, Exception) → except ValueError in llm_utils.py and main.py
- Re-add LLM API key migration at startup with correct exception handling
- Remove unused imports: decrypt_data (task_executor), get_current_user/check_agent_access/is_agent_creator (gateway)
- Remove dead imports from gateway.py: secrets, BackgroundTasks, update

* fix: correct app.core.config → app.config in llm_utils

---------

Co-authored-by: 沈锋 <shenfeng@shenfengdeMac-mini.local>
Co-authored-by: yaojin <yaojin@58.com>
Co-authored-by: 姚劲 <yaojin@dataelem.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants