Skip to content

User context sensitive env filtering uses substring matching #148

Open

Description

@abenneto

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions