FAROS
FAROS copied to clipboard
User context sensitive env filtering uses substring matching
User context sensitive env filtering uses substring matching
Severity: Medium
File: backend/app/core/user_context.py:95
The sanitized_subprocess_env function filters environment variables by checking if sensitive markers like "API_KEY", "AUTH_TOKEN", etc. appear in the variable name (case-insensitive). This can miss variants like APIKEY (no underscore) or api_key_custom.
_SENSITIVE_ENV_MARKERS = (
"API_KEY",
"AUTH_TOKEN",
"ACCESS_TOKEN",
"REFRESH_TOKEN",
"PRIVATE_KEY",
"PASSWORD",
"CREDENTIAL",
"CLIENT_SECRET",
)
def sanitized_subprocess_env(extra: Optional[dict[str, str]] = None) -> dict[str, str]:
"""Return the process environment without application or provider secrets."""
sanitized = {}
for name, value in os.environ.items():
upper_name = name.upper()
if upper_name in _SENSITIVE_ENV_EXACT:
continue
if any(marker in upper_name for marker in _SENSITIVE_ENV_MARKERS):
continue
sanitized[name] = value
Why it matters
Sensitive credentials with non-standard naming conventions leak into subprocess environments, potentially exposing them to user-executed code.