Skip to content

fix(security): refuse every loader and shell key that loads code into a child - #2405

Merged
dan-petty merged 4 commits into
mainfrom
fix/2205-refuse-code-loading-env-keys
Oct 28, 2026
Merged

dan-petty merged 4 commits into
mainfrom
fix/2205-refuse-code-loading-env-keys

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

build_subprocess_env in src/devops_cli/core/process.py refused a caller override of six keys only: LD_PRELOAD, LD_LIBRARY_PATH, DYLD_INSERT_LIBRARIES, DYLD_LIBRARY_PATH, BASH_ENV and ENV. It accepted other keys that make the loader or the shell of a child load code that the caller did not choose. glibc loads each object that LD_AUDIT names. The macOS loader reads more DYLD_ keys, for example DYLD_FRAMEWORK_PATH. A bash child defines a function from each BASH_FUNC_<name>%% key, and that function replaces a command of the same name.

  • The new constant CONST_CODE_LOADING_ENV_PATTERNS in src/devops_cli/config/constants.py holds the refused families as fnmatch patterns: LD_AUDIT, LD_LIBRARY_PATH, LD_ORIGIN_PATH, LD_PRELOAD, DYLD_*, BASH_ENV, ENV and BASH_FUNC_*. Its comment names the sources: glibc ld.so(8), macOS dyld(1) and the function export of bash.
  • build_subprocess_env matches the upper-case key of each caller override against the constant with _is_env_var_denied, the helper of the credential patterns. A match raises the same SecurityError and error code as before. The local key set of the function is deleted.
  • run_rule_pack_tests in src/devops_cli/review/rules_pack.py gave Semgrep the full ambient environment as its override. The wider guard thus stopped devops review rules test on a host where bash exports a function, such as which on Fedora and RHEL. The full copy also gave Semgrep the credentials that build_subprocess_env removes. Semgrep now gets only SEMGREP_ENABLE_VERSION_CHECK=0 on top of the isolated environment.
  • tests/test_subprocess_env_boundary.py adds LD_AUDIT, LD_ORIGIN_PATH, three DYLD_ keys and BASH_FUNC_x%% to the refused keys, in upper and lower case. A new test shows that PATH, HOME, ENVIRONMENT, EXAMPLE_DYLD_FLAG and BASH_FUNCTIONS reach the child. tests/test_review_rules_pack.py shows that Semgrep gets only its own setting.
  • ARCHITECTURE.md describes the guard in its section on safe subprocess execution.
  • The OpenSpec change records the premise check, the rejected alternatives and the new capability subprocess-environment.

Closes #2205

Change: openspec/changes/2205-refuse-code-loading-env-keys/

Plan #2205 as the change 2205-refuse-code-loading-env-keys: the proposal with its feasibility evidence, the design, the spec delta of the new capability subprocess-environment, and the tasks.
… a child

build_subprocess_env refused six keys only. It now refuses a caller override whose upper-case key matches CONST_CODE_LOADING_ENV_PATTERNS: LD_AUDIT, LD_LIBRARY_PATH, LD_ORIGIN_PATH, LD_PRELOAD, every DYLD_ key, BASH_ENV, ENV and every BASH_FUNC_ key. The constant names its sources, glibc ld.so(8), macOS dyld(1) and bash function export. The local key set of the function is deleted.
…f the person

run_rule_pack_tests gave Semgrep the full ambient environment as its caller override. The guard on code-loading keys checks each override key, so an exported bash function in the environment, such as which on Fedora and RHEL, stopped devops review rules test. The full copy also gave Semgrep the credentials that build_subprocess_env removes. Semgrep now gets only SEMGREP_ENABLE_VERSION_CHECK=0 on top of the isolated environment.
The safe subprocess execution section says which caller keys build_subprocess_env refuses, and that a caller gives a child only the keys that it needs.
@dan-petty dan-petty added scope/security Security linters (trivy, bandit, gitleaks, kubeconform) and Vault type/security Type security: a vulnerability or a leak labels Oct 28, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Test results of the branch at 0afbce7, rebased onto origin/main at ad0114f.

  • uv run devops ci test tests/test_subprocess_env_boundary.py tests/test_review_rules_pack.py: 101 passed.
  • uv run devops ci test on the related files (test_subprocess_env_boundary, test_review_rules_pack, test_process, test_process_contract, test_architectural_invariants, test_change_folders, test_agent_invariants, test_zero_plaintext_invariants, invariants/test_hermetic_floor, test_openspec_gate): 294 passed.
  • ruff check and ruff format --check on the changed Python files: passed. uv run devops openspec check and uv run devops ci docs: passed. The pre-push hook passed.
  • semgrep 1.179.0 --version and semgrep --test --metrics off src/devops_cli/review/rules passed with the environment that build_subprocess_env({"SEMGREP_ENABLE_VERSION_CHECK": "0"}) builds ("1/1: All tests passed").

Fail-to-pass (uv run devops ci fail-to-pass --base origin/main): 25 tests failed on the base and pass on the branch.

25 failed on base (25 failed and 76 passed in tests/test_review_rules_pack.py, tests/test_subprocess_env_boundary.py; 0 errored).
failed on base: tests.test_review_rules_pack::test_semgrep_gets_only_its_own_setting_and_not_the_environment_of_the_person (AssertionError: assert [('--version'...'less', ...})] == [('--version'...CHECK': '0'})])
failed on base: tests.test_subprocess_env_boundary::test_a_caller_override_that_loads_code_into_the_child_is_refused[BASH_FUNC_x%%-isolated] (Failed: DID NOT RAISE SecurityError)
failed on base: tests.test_subprocess_env_boundary::test_a_caller_override_that_loads_code_into_the_child_is_refused[BASH_FUNC_x%%-not-isolated] (Failed: DID NOT RAISE SecurityError)
failed on base: tests.test_subprocess_env_boundary::test_a_caller_override_that_loads_code_into_the_child_is_refused[DYLD_FALLBACK_FRAMEWORK_PATH-isolated] (Failed: DID NOT RAISE SecurityError)
failed on base: tests.test_subprocess_env_boundary::test_a_caller_override_that_loads_code_into_the_child_is_refused[DYLD_FALLBACK_FRAMEWORK_PATH-not-isolated] (Failed: DID NOT RAISE SecurityError)
failed on base: tests.test_subprocess_env_boundary::test_a_caller_override_that_loads_code_into_the_child_is_refused[DYLD_FALLBACK_LIBRARY_PATH-isolated] (Failed: DID NOT RAISE SecurityError)
failed on base: tests.test_subprocess_env_boundary::test_a_caller_override_that_loads_code_into_the_child_is_refused[DYLD_FALLBACK_LIBRARY_PATH-not-isolated] (Failed: DID NOT RAISE SecurityError)
failed on base: tests.test_subprocess_env_boundary::test_a_caller_override_that_loads_code_into_the_child_is_refused[DYLD_FRAMEWORK_PATH-isolated] (Failed: DID NOT RAISE SecurityError)
failed on base: tests.test_subprocess_env_boundary::test_a_caller_override_that_loads_code_into_the_child_is_refused[DYLD_FRAMEWORK_PATH-not-isolated] (Failed: DID NOT RAISE SecurityError)
failed on base: tests.test_subprocess_env_boundary::test_a_caller_override_that_loads_code_into_the_child_is_refused[LD_AUDIT-isolated] (Failed: DID NOT RAISE SecurityError)
failed on base: tests.test_subprocess_env_boundary::test_a_caller_override_that_loads_code_into_the_child_is_refused[LD_AUDIT-not-isolated] (Failed: DID NOT RAISE SecurityError)
failed on base: tests.test_subprocess_env_boundary::test_a_caller_override_that_loads_code_into_the_child_is_refused[LD_ORIGIN_PATH-isolated] (Failed: DID NOT RAISE SecurityError)
failed on base: tests.test_subprocess_env_boundary::test_a_caller_override_that_loads_code_into_the_child_is_refused[LD_ORIGIN_PATH-not-isolated] (Failed: DID NOT RAISE SecurityError)
failed on base: tests.test_subprocess_env_boundary::test_a_caller_override_that_loads_code_into_the_child_is_refused[bash_func_x%%-isolated] (Failed: DID NOT RAISE SecurityError)
failed on base: tests.test_subprocess_env_boundary::test_a_caller_override_that_loads_code_into_the_child_is_refused[bash_func_x%%-not-isolated] (Failed: DID NOT RAISE SecurityError)
failed on base: tests.test_subprocess_env_boundary::test_a_caller_override_that_loads_code_into_the_child_is_refused[dyld_fallback_framework_path-isolated] (Failed: DID NOT RAISE SecurityError)
failed on base: tests.test_subprocess_env_boundary::test_a_caller_override_that_loads_code_into_the_child_is_refused[dyld_fallback_framework_path-not-isolated] (Failed: DID NOT RAISE SecurityError)
failed on base: tests.test_subprocess_env_boundary::test_a_caller_override_that_loads_code_into_the_child_is_refused[dyld_fallback_library_path-isolated] (Failed: DID NOT RAISE SecurityError)
failed on base: tests.test_subprocess_env_boundary::test_a_caller_override_that_loads_code_into_the_child_is_refused[dyld_fallback_library_path-not-isolated] (Failed: DID NOT RAISE SecurityError)
failed on base: tests.test_subprocess_env_boundary::test_a_caller_override_that_loads_code_into_the_child_is_refused[dyld_framework_path-isolated] (Failed: DID NOT RAISE SecurityError)
failed on base: tests.test_subprocess_env_boundary::test_a_caller_override_that_loads_code_into_the_child_is_refused[dyld_framework_path-not-isolated] (Failed: DID NOT RAISE SecurityError)
failed on base: tests.test_subprocess_env_boundary::test_a_caller_override_that_loads_code_into_the_child_is_refused[ld_audit-isolated] (Failed: DID NOT RAISE SecurityError)
failed on base: tests.test_subprocess_env_boundary::test_a_caller_override_that_loads_code_into_the_child_is_refused[ld_audit-not-isolated] (Failed: DID NOT RAISE SecurityError)
failed on base: tests.test_subprocess_env_boundary::test_a_caller_override_that_loads_code_into_the_child_is_refused[ld_origin_path-isolated] (Failed: DID NOT RAISE SecurityError)
failed on base: tests.test_subprocess_env_boundary::test_a_caller_override_that_loads_code_into_the_child_is_refused[ld_origin_path-not-isolated] (Failed: DID NOT RAISE SecurityError)

@dan-petty
dan-petty marked this pull request as ready for review October 28, 2026 14:13
@dan-petty
dan-petty merged commit 86d5bce into main Oct 28, 2026
16 of 18 checks passed
@dan-petty
dan-petty deleted the fix/2205-refuse-code-loading-env-keys branch October 28, 2026 14:13
dan-petty pushed a commit that referenced this pull request Oct 28, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.8.3](v0.8.2...v0.8.3)
(2026-10-28)


### Bug Fixes

* **ai:** the gateway sweep's URL error names no credential
([#2400](#2400))
([2e6f1fd](2e6f1fd)),
closes [#909](#909)
* **config:** exit 1 when audit-keys finds a plaintext secret
([#2401](#2401))
([ad0114f](ad0114f)),
closes [#1469](#1469)
* **security:** drop the Go ignores that the pinned gh build does not
need ([#2402](#2402))
([6052083](6052083)),
closes [#1492](#1492)
* **security:** refuse every loader and shell key that loads code into a
child ([#2405](#2405))
([86d5bce](86d5bce)),
closes [#2205](#2205)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/security Security linters (trivy, bandit, gitleaks, kubeconform) and Vault type/security Type security: a vulnerability or a leak

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant