Skip to content

fix(security): the subprocess environment guard refuses ld_audit, every dyld_ key and exported bash functions #2205

Description

@dan-petty

What happened

build_subprocess_env in src/devops_cli/core/process.py refuses six environment keys that make a child process load or run code that the caller did not choose: LD_PRELOAD, LD_LIBRARY_PATH, DYLD_INSERT_LIBRARIES, DYLD_LIBRARY_PATH, BASH_ENV and ENV (and null bytes). #2151 (2026-10-25) tested that set. It does not refuse other keys of the same kind:

  • LD_AUDIT (glibc loads each named audit library into the child, like LD_PRELOAD);
  • the other DYLD_* keys of the macOS loader, for example DYLD_FRAMEWORK_PATH, DYLD_FALLBACK_LIBRARY_PATH and DYLD_FALLBACK_FRAMEWORK_PATH;
  • exported bash functions (BASH_FUNC_<name>%%), which a bash child defines at start.

What should happen

The guard refuses every key of these families: LD_AUDIT with the other glibc keys that load code, every DYLD_ key, and every BASH_FUNC_ key, in upper and lower case, with the same SecurityError and error code as today. The set is one constant with a comment that names its source (the glibc ld.so(8) and the macOS dyld(1) manual pages, and bash's function export format).

Acceptance criteria

  • Parametrized tests in tests/test_subprocess_env_boundary.py show that LD_AUDIT, DYLD_FRAMEWORK_PATH, DYLD_FALLBACK_LIBRARY_PATH and BASH_FUNC_x%% raise SecurityError, and that a usual key such as PATH or HOME does not.

Source: #2151

Proposed design

Problem statement

The subprocess environment guard in build_subprocess_env refuses six dangerous keys but misses other keys of the same kind: LD_AUDIT, every DYLD_ key, and every BASH_FUNC_ key. A caller can override these keys to make a child process load or run code that the caller did not choose. The guard must refuse all keys of these families with the same SecurityError and error code.

Acceptance criteria

  • Criterion 1: LD_AUDIT in upper and lower case raises SecurityError with the same message format and error code as the existing refused keys.
    Verification: Run the parametrized test in tests/test_subprocess_env_boundary.py with keys LD_AUDIT and ld_audit. Both raise SecurityError with message 'Prohibited dangerous environment variable override: ' and error code CONST_ERROR_CODE_SECURITY.
  • Criterion 2: DYLD_FRAMEWORK_PATH, DYLD_FALLBACK_LIBRARY_PATH, DYLD_FALLBACK_FRAMEWORK_PATH and any other DYLD_ key raise SecurityError.
    Verification: Run the parametrized test with DYLD_FRAMEWORK_PATH, DYLD_FALLBACK_LIBRARY_PATH, DYLD_FALLBACK_FRAMEWORK_PATH and their lower-case forms. Each raises SecurityError with the same message and error code.
  • Criterion 3: BASH_FUNC_x%% and any BASH_FUNC_ key raise SecurityError.
    Verification: Run the parametrized test with BASH_FUNC_x%% and bash_func_x%%. Each raises SecurityError with the same message and error code.
  • Criterion 4: Usual keys such as PATH and HOME do not raise SecurityError when passed as caller overrides.
    Verification: Run build_subprocess_env(env={'PATH': '/usr/bin', 'HOME': '/home/u'}). No exception is raised and both keys appear in the returned dict.
  • Criterion 5: The refused keys and prefixes are defined as one named constant in src/devops_cli/core/process.py with a comment that names the source: glibc ld.so(8), macOS dyld(1), and bash function export format.
    Verification: Inspect src/devops_cli/core/process.py. The constant is a single assignment with a comment citing ld.so(8), dyld(1), and the bash function export format.

Key questions

  • Should DYLD_ and BASH_FUNC_ be matched by prefix rather than by an explicit list of keys?: Yes. The body states 'every DYLD_ key' and 'every BASH_FUNC_ key', which requires prefix matching. LD_AUDIT is added as an exact key alongside the existing glibc keys. The constant holds both the exact-key set and the prefix tuple. (proposed)
  • Where is the current dangerous-key set defined and checked?: The set is a local variable dangerous_env_keys inside build_subprocess_env at src/devops_cli/core/process.py, checked with k.upper() in dangerous_env_keys. The test file tests/test_subprocess_env_boundary.py defines REFUSED_OVERRIDE_KEYS as the current six keys for its parametrized test. [sources: src/devops_cli/core/process.py, tests/test_subprocess_env_boundary.py:159]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/security
    on Oct 25, 2026
  2. dan-petty commented on Oct 25, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.

    • Type: type/security. The candidate fixes a security issue in subprocess environment handling.
    • Priority: P1-High. Security issues that affect process isolation are prioritized as high.
    • Value: High. Fixing environment variable guards improves system security for all users.
    • Effort: Medium. Adding new environment keys to the guard requires code changes and tests but is not overly complex.
    • Related: feat(cli): sandbox enforcement audit declared vs engine vs enforced (devops sandbox audit) #698, which asks for a different change. Both items relate to sandboxing but the candidate fixes environment guards while item 698 adds a sandbox enforcement audit command.
  3. dan-petty commented on Oct 27, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at 520e8b8 (see proposed design in issue body).

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

    source/agenttype/security

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions