[BUG] Action Schema: Potential for Environment Variable Exfiltration #9089

Open
opened 2026-04-14 07:26:23 +00:00 by HAL9000 · 0 comments
Owner

Metadata

  • Commit Message: fix(action): restrict env var interpolation in action YAML to allowlisted prefixes
  • Branch: fix/action-schema-env-var-exfiltration

Background and Context

The _interpolate_env_vars function in src/cleveragents/action/schema.py allows action YAML files to reference and embed the values of any environment variable on the system via ${VAR} placeholders. This creates a security vulnerability where an attacker could craft a malicious action YAML file to exfiltrate sensitive environment variables, such as API keys, database credentials, or other secrets present in the process environment.

The vulnerable function is _interpolate_env_vars (and its helper _env_replacer) in src/cleveragents/action/schema.py. The _env_replacer function calls os.environ.get(var_name, match.group(0)) with no restriction on which variable names are permitted, meaning any ${SECRET_KEY}, ${DATABASE_PASSWORD}, ${AWS_SECRET_ACCESS_KEY}, etc. can be embedded into an action configuration and subsequently logged, transmitted, or stored.

Code Reference:
src/cleveragents/action/schema.py_interpolate_env_vars / _env_replacer functions

Impact:
This vulnerability could lead to the leakage of sensitive credentials and other confidential information. Any user or process that can supply or modify an action YAML file (e.g., via a malicious action in a shared namespace) could exfiltrate arbitrary environment variables from the host process, posing a significant security risk.

Expected Behavior

The _interpolate_env_vars function should only allow interpolation of environment variables that match an explicit allowlist or naming convention. For example, only variables with a specific prefix (e.g., CLEVERAGENTS_) should be eligible for interpolation. Attempts to reference variables outside the allowlist should either be left as-is (current behavior for missing vars) or raise a ValueError with a clear message.

Acceptance Criteria

  • _interpolate_env_vars only interpolates environment variables whose names match an allowlist or a permitted prefix (e.g., CLEVERAGENTS_)
  • Attempts to reference disallowed environment variables (e.g., ${AWS_SECRET_ACCESS_KEY}) are either left as the literal ${VAR} placeholder or raise a clear ValueError
  • Existing tests for ActionConfigSchema continue to pass with the restricted interpolation
  • New BDD scenarios cover: allowed prefix variables are interpolated, disallowed variables are not interpolated (or raise an error), and edge cases (empty prefix, mixed case)
  • No regression in from_yaml / from_yaml_file factory methods

Subtasks

  • Define the allowlist/prefix constant (e.g., _ALLOWED_ENV_VAR_PREFIX = "CLEVERAGENTS_") in src/cleveragents/action/schema.py
  • Update _env_replacer to check the variable name against the allowlist/prefix before calling os.environ.get
  • Update _interpolate_env_vars docstring to document the restriction
  • Tests (Behave): Add scenarios for allowed and disallowed env var interpolation in action YAML
  • Tests (Behave): Add scenario verifying that sensitive variable names (e.g., AWS_SECRET_ACCESS_KEY) are not interpolated
  • Verify coverage >=97% via nox -s coverage_report
  • Run nox (all default sessions), fix any errors

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly.
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.

Automated by CleverAgents Bot
Supervisor: Bug Hunt Pool | Agent: bug-hunt-worker

## Metadata - **Commit Message**: `fix(action): restrict env var interpolation in action YAML to allowlisted prefixes` - **Branch**: `fix/action-schema-env-var-exfiltration` ## Background and Context The `_interpolate_env_vars` function in `src/cleveragents/action/schema.py` allows action YAML files to reference and embed the values of **any** environment variable on the system via `${VAR}` placeholders. This creates a security vulnerability where an attacker could craft a malicious action YAML file to exfiltrate sensitive environment variables, such as API keys, database credentials, or other secrets present in the process environment. The vulnerable function is `_interpolate_env_vars` (and its helper `_env_replacer`) in `src/cleveragents/action/schema.py`. The `_env_replacer` function calls `os.environ.get(var_name, match.group(0))` with no restriction on which variable names are permitted, meaning any `${SECRET_KEY}`, `${DATABASE_PASSWORD}`, `${AWS_SECRET_ACCESS_KEY}`, etc. can be embedded into an action configuration and subsequently logged, transmitted, or stored. **Code Reference:** `src/cleveragents/action/schema.py` — `_interpolate_env_vars` / `_env_replacer` functions **Impact:** This vulnerability could lead to the leakage of sensitive credentials and other confidential information. Any user or process that can supply or modify an action YAML file (e.g., via a malicious action in a shared namespace) could exfiltrate arbitrary environment variables from the host process, posing a significant security risk. ## Expected Behavior The `_interpolate_env_vars` function should only allow interpolation of environment variables that match an explicit allowlist or naming convention. For example, only variables with a specific prefix (e.g., `CLEVERAGENTS_`) should be eligible for interpolation. Attempts to reference variables outside the allowlist should either be left as-is (current behavior for missing vars) or raise a `ValueError` with a clear message. ## Acceptance Criteria - [ ] `_interpolate_env_vars` only interpolates environment variables whose names match an allowlist or a permitted prefix (e.g., `CLEVERAGENTS_`) - [ ] Attempts to reference disallowed environment variables (e.g., `${AWS_SECRET_ACCESS_KEY}`) are either left as the literal `${VAR}` placeholder or raise a clear `ValueError` - [ ] Existing tests for `ActionConfigSchema` continue to pass with the restricted interpolation - [ ] New BDD scenarios cover: allowed prefix variables are interpolated, disallowed variables are not interpolated (or raise an error), and edge cases (empty prefix, mixed case) - [ ] No regression in `from_yaml` / `from_yaml_file` factory methods ## Subtasks - [ ] Define the allowlist/prefix constant (e.g., `_ALLOWED_ENV_VAR_PREFIX = "CLEVERAGENTS_"`) in `src/cleveragents/action/schema.py` - [ ] Update `_env_replacer` to check the variable name against the allowlist/prefix before calling `os.environ.get` - [ ] Update `_interpolate_env_vars` docstring to document the restriction - [ ] Tests (Behave): Add scenarios for allowed and disallowed env var interpolation in action YAML - [ ] Tests (Behave): Add scenario verifying that sensitive variable names (e.g., `AWS_SECRET_ACCESS_KEY`) are not interpolated - [ ] Verify coverage >=97% via `nox -s coverage_report` - [ ] Run `nox` (all default sessions), fix any errors ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation. - The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly. - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunt Pool | Agent: bug-hunt-worker
HAL9000 added this to the v3.5.0 milestone 2026-04-14 07:37:30 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
cleveragents/cleveragents-core#9089
No description provided.