[SECURITY] Fix Secret Leakage via Environment Variables (CVSS 9.3) #58

Merged
allegro merged 1 commits from security/fix-secret-leakage into main 2026-03-30 23:43:03 +00:00
Member

Security Fix: Secret Leakage via Environment Variables (CVSS 9.3)

Summary

Fixes critical secret leakage vulnerability where child processes could inherit sensitive environment variables containing API keys and credentials.

Changes

  • tools/code_execution_tool.py:
    • Replace blacklist with explicit whitelist approach
    • Only 30+ explicitly allowed env vars pass to child processes
    • All other variables silently dropped

Vulnerability Details

  • CVSS Score: 9.3 (Critical)
  • Attack Vector: Malicious code executed via execute_code
  • Impact: API key theft, credential exfiltration

Before (Vulnerable)

# Blacklist approach - easily bypassed
_SECRET_SUBSTRINGS = ("KEY", "TOKEN", "SECRET", ...)
if any(s in k.upper() for s in _SECRET_SUBSTRINGS):
    continue  # MY_API_KEY_XYZ bypasses this!

After (Secure)

# Whitelist approach - only explicit allowed
_ALLOWED_ENV_VARS = frozenset(["PATH", "HOME", "USER", ...])
if k in _ALLOWED_ENV_VARS:
    child_env[k] = v
# All others dropped

Security References

  • V-003 in SECURITY_AUDIT_REPORT.md
  • CWE-526: Exposure of Sensitive Information
## Security Fix: Secret Leakage via Environment Variables (CVSS 9.3) ### Summary Fixes critical secret leakage vulnerability where child processes could inherit sensitive environment variables containing API keys and credentials. ### Changes - **tools/code_execution_tool.py**: - Replace blacklist with explicit whitelist approach - Only 30+ explicitly allowed env vars pass to child processes - All other variables silently dropped ### Vulnerability Details - **CVSS Score**: 9.3 (Critical) - **Attack Vector**: Malicious code executed via `execute_code` - **Impact**: API key theft, credential exfiltration ### Before (Vulnerable) ```python # Blacklist approach - easily bypassed _SECRET_SUBSTRINGS = ("KEY", "TOKEN", "SECRET", ...) if any(s in k.upper() for s in _SECRET_SUBSTRINGS): continue # MY_API_KEY_XYZ bypasses this! ``` ### After (Secure) ```python # Whitelist approach - only explicit allowed _ALLOWED_ENV_VARS = frozenset(["PATH", "HOME", "USER", ...]) if k in _ALLOWED_ENV_VARS: child_env[k] = v # All others dropped ``` ### Security References - V-003 in SECURITY_AUDIT_REPORT.md - CWE-526: Exposure of Sensitive Information
allegro added 1 commit 2026-03-30 23:43:01 +00:00
security: fix secret leakage via whitelist-only env vars (CVSS 9.3)
Some checks failed
Supply Chain Audit / Scan PR for supply chain risks (pull_request) Successful in 32s
Tests / test (pull_request) Failing after 30s
Docker Build and Publish / build-and-push (pull_request) Failing after 55s
08abea4905
Replace blacklist approach with explicit whitelist for child process
environment variables to prevent secret exfiltration via creative naming.

Changes:
- tools/code_execution_tool.py: Implement _ALLOWED_ENV_VARS frozenset
- Only pass explicitly listed env vars to sandboxed child processes
- Drop all other variables silently to prevent credential theft

Fixes CWE-526: Exposure of Sensitive Information to an Unauthorized Actor

CVSS: 9.3 (Critical)
Refs: V-003 in SECURITY_AUDIT_REPORT.md
allegro merged commit 05000f091f into main 2026-03-30 23:43:03 +00:00
Sign in to join this conversation.