Skip to content

fix(security): patch 4 critical vulnerabilities#246

Open
Frankshen923 wants to merge 1 commit intodataelement:mainfrom
Frankshen923:fix/security-audit
Open

fix(security): patch 4 critical vulnerabilities#246
Frankshen923 wants to merge 1 commit intodataelement:mainfrom
Frankshen923:fix/security-audit

Conversation

@Frankshen923
Copy link
Copy Markdown

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
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.

1 participant