Skip to content

fix(security): the subprocess environment guard accepts LESS, which makes less run a program #2735

Closed

Description

@dan-petty

Problem Description

build_subprocess_env in src/devops_cli/core/process.py refuses LESSOPEN and LESSCLOSE (#2205, #2483) but accepts LESS. less(1) reads options from LESS, and an option that starts with + is a command that less runs at start. The command !<program> makes less run a shell command. Git runs less as its default pager, and gh runs the pager of GH_PAGER or PAGER, so a caller override of LESS is a code path for git and gh children.

The independent review of #2672 (PR #2732) probed this with real less 668 in a pseudo-terminal, a temporary HOME and a marker program that prints a line. The probe is not mine: I report its result.

  • LESS with the value +!<marker> and a trailing newline made git --paginate help -a run the marker.
  • The same value made GH_PAGER=less gh help reference run the marker.
  • build_subprocess_env(env={"LESS": "+!x\n"}) returns the key unchanged.

Reproduction Steps

  1. Run uv run python -c 'from devops_cli.core.process import build_subprocess_env as b; print(b(env={"LESS": "+!x\n"})["LESS"])'.
  2. In a temporary directory <dir>, write an executable <dir>/marker that runs echo MARKER-RAN >&2.
  3. In a pseudo-terminal, run env -i PATH=/usr/bin:/bin HOME=<dir> LESS="+!<dir>/marker " git --paginate help -a.

Expected vs Actual Behavior

Expected: build_subprocess_env raises SecurityError for a caller override of LESS, or the design names the reason to accept it. Actual: it returns LESS with no error, and a child that starts less runs the program.

Environment Diagnostics

Logs, Traces, or Terminal Output

MARKER-RAN

Pre-Submission Checklist

  • I have verified that no sensitive credentials, private keys, or internal tokens are contained in this issue report.
  • I have checked existing issues and pull requests to ensure this is not a duplicate.

Proposed design

Problem statement

The subprocess environment guard in build_subprocess_env refuses LESSOPEN and LESSCLOSE but accepts LESS. The less(1) pager reads options from LESS, and an option that starts with + is a command that less runs at start. The ! option makes less run a shell command. Git and gh use less as their default pager, so a caller override of LESS is a code-execution path for their children. A probe with less 668 confirmed that LESS=+! made git --paginate and gh help reference run the marker program.

Acceptance criteria

Requirement: Refuse LESS override

build_subprocess_env SHALL raise SecurityError when a caller overrides the key LESS, in upper or lower case.

Scenario: Caller sets LESS to a command string

  • WHEN A caller calls build_subprocess_env with env={"LESS": "+!x\n"}
  • THEN The call raises SecurityError with the message "Prohibited dangerous environment variable override: 'LESS'"

Requirement: Refuse LESS with isolation off

build_subprocess_env SHALL raise SecurityError for a LESS override when isolate_env is False.

Scenario: Caller sets LESS with isolation disabled

  • WHEN A caller calls build_subprocess_env with env={"LESS": "+!x\n"} and isolate_env=False
  • THEN The call raises SecurityError with the same message

Requirement: Do not refuse LESSOPEN or LESSCLOSE

The refusal of LESS SHALL NOT change the existing refusal of LESSOPEN and LESSCLOSE.

Scenario: Caller sets LESSOPEN after the fix

  • WHEN A caller calls build_subprocess_env with env={"LESSOPEN": "|x %s"}
  • THEN The call raises SecurityError as before

Existing Tool Considered

No check has run. No open, maintained tool or library covers this need. The project builds its own environment guard in src/devops_cli/core/process.py. The written cost is one key added to a constant in src/devops_cli/config/constants.py and one test case in the existing test file for build_subprocess_env.

Key questions

  • Where is the list of refused environment variable keys defined?: The constant CONST_CODE_LOADING_ENV_PATTERNS in src/devops_cli/config/constants.py holds the patterns. The function _is_env_override_refused in src/devops_cli/core/process.py checks a caller key against this constant via _is_env_var_denied, which uses fnmatch.fnmatchcase for full-string matching. [sources: src/devops_cli/core/process.py, openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/specs/subprocess-environment/spec.md]
  • Should LESS be refused or accepted by the guard?: Refuse it. The less(1) manual documents that LESS holds options and that +! runs a shell command. The guard already refuses LESSOPEN and LESSCLOSE for the same reason (less runs a filter program). The fix(security): the subprocess environment guard accepts the git keys that make a git child run a program #2483 spec and ARCHITECTURE.md record the pattern: a key that makes a child run a program is refused. No file in src/ sets or reads LESS for a child, so refusing it breaks no existing caller. (best practice) [sources: openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/specs/subprocess-environment/spec.md, openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/design.md, ARCHITECTURE.md]
  • Does any code in the project set or read LESS for a child process?: No. The fix(security): the subprocess environment guard accepts the git keys that make a git child run a program #2483 design doc states that no file of src/ sets or reads the refused pager keys for a child, and no test sets one. The same applies to LESS: it is not in DEFAULT_ALLOWED_ENV_VARS, not in any prefix, and no caller passes it in extra_allowed_env. [sources: openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/design.md, src/devops_cli/core/process.py]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/bug
    scope/security
    status/new
    value/high
    effort/low
    on Oct 30, 2026
  2. dan-petty commented on Oct 30, 2026

    @dan-petty
    OwnerAuthor

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

    • Type: type/bug. The fix prefix of the title gives the type.
    • Scope: scope/security. The (security) scope of the title gives the scope.
    • Priority: P1-High. A confirmed arbitrary-code-execution path via LESS is a security defect with a working proof of concept.
    • Value: High. Closing this removes a code-execution vector reachable through git and gh child processes.
    • Effort: Low. The fix adds LESS to the refused-key list, matching the pattern already used for LESSOPEN and LESSCLOSE.
    • Related: fix(security): the subprocess environment guard accepts the git keys that make a git child run a program #2483, which asks for a different change. Both target build_subprocess_env in the same file and both use git as the execution vector, but #2483 covers GIT_* keys while the candidate covers LESS.
  3. added
    priority/p1-high
    on Oct 30, 2026
  4. added
    status/ready
    and removed
    status/new
    on Oct 30, 2026
  5. devops-cli-service commented on Oct 30, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 07fb4c2 (see proposed design in issue body).

  6. devops-cli-service commented on Oct 30, 2026

    @devops-cli-service
    Contributor

    The stage job stopped. The inputs of the step of the task group "Add LESS to the refused environment patterns" hold 41179 tokens, over the budget of 40000 tokens, also after the model split the groups once. A person decides how to split the item. The job stages the item again when a person runs it with --item 2735.

    The task groups:

    1. Write failing tests for LESS and LESSOPEN environment guard: 8060 tokens
    2. Add LESS to the refused environment patterns: 41179 tokens
  7. devops-cli-service commented on Oct 31, 2026

    @devops-cli-service
    Contributor

    Staged: branch fix/2735-the-subprocess-environment-guard-accepts-less, draft pull request #2858. The pull request plans the item and closes no issue.

    The task groups, with the tokens of the inputs of each step, for a budget of 40000 tokens:

    1. Add LESS to the denied patterns and test it: 3055 tokens

    These paths of the plan are no file on the default branch, and no group creates them: tests/test_process.py. A person checks that the plan names them right.

  8. added
    status/in-progress
    and removed
    status/ready
    on Oct 31, 2026
  9. added a commit that references this issue on Oct 31, 2026
  10. devops-cli-service commented on Oct 31, 2026

    @devops-cli-service
    Contributor

    Stopped at group 1.

    Reason:

    UnexpectedModelBehavior: Tool 'edit_file' exceeded max retries count of 5. Consider raising the retry limit, or see the docs on tool retries: https://pydantic.dev/docs/ai/tools-toolsets/tools-advanced/#tool-retries
    Refused commands: 0. Other retries: 6.
    

    Last message of the agent: Let me just add it directly at the end of the file:

    The job discarded this work. Read it before you retry:

    diff --git a/tests/core/test_subprocess_env_boundary.py b/tests/core/test_subprocess_env_boundary.py
    index d8c42f8f..62adb634 100644
    --- a/tests/core/test_subprocess_env_boundary.py
    +++ b/tests/core/test_subprocess_env_boundary.py
    @@ -248,6 +248,7 @@ REFUSED_OVERRIDE_KEYS: tuple[str, ...] = (
         "PAGER",
         "LESSOPEN",
         "LESSCLOSE",
    +    "LESS",
         "SSH_ASKPASS",
         "SSH_ASKPASS_REQUIRE",
         "SSH_SK_PROVIDER",
    diff --git a/tmp_test_addition.py b/tmp_test_addition.py
    new file mode 100644
    index 00000000..3ac3aea8
    --- /dev/null
    +++ b/tmp_test_addition.py
    @@ -0,0 +1,13 @@
    +def test_build_subprocess_env_less_security() -> None:
    +    """Verify that LESS environment variable is refused for security reasons."""
    +    # Test that LESS is refused with a SecurityError
    +    with pytest.raises(SecurityError, match="Prohibited dangerous environment variable override: 'LESS'"):
    +        build_subprocess_env(env={"LESS": "+!x\\n"})
    +    
    +    # Test that LESS with isolation disabled is also refused  
    +    with pytest.raises(SecurityError, match="Prohibited dangerous environment variable override: 'LESS'"):
    +        build_subprocess_env(env={"LESS": "+!x\\n"}, isolate_env=False)
    +
    +    # Verify that LESSOPEN still raises SecurityError (regression test)
    +    with pytest.raises(SecurityError, match="Prohibited dangerous environment variable override: 'LESSOPEN'"):
    +        build_subprocess_env(env={"LESSOPEN": "|x %s"})
    \ No newline at end of file

    The item is Ready again, and the job will not run it. Fix the cause. Then comment implement: retry.

  11. added
    status/ready
    and removed
    status/in-progress
    on Oct 31, 2026
  12. devops-cli-service commented on Oct 31, 2026

    @devops-cli-service
    Contributor

    The runner Job devops-cli-runner-20261031-125802-ebfe ended: succeeded.

    The last lines of its log:

    b'# Implement plan for dan-petty/devops-cli\n\n## To implement\n- #2735 fix(security): the subprocess environment guard accepts LESS, which makes less run a program: branch `fix/2735-the-subprocess-environment-guard-accepts-less`, pull request #2858\nTool call: read_file, ok.\nTool call: grep, ok.\nTool call: read_file, ok.\nTool call: read_file, ok.\nTool call: read_file, ok.\nTool call: read_file, ok.\nTool call: read_file, ok.\nTool call: list_files, ok.\nTool call: read_file, ok.\nTool call: read_file, ok.\nTool call: grep, ok.\nTool call: read_file, ok.\nTool call: read_file, ok.\nTool call: edit_file, ok.\nTool call: edit_file, retry.\nTool call: edit_file, retry.\nTool call: edit_file, retry.\nTool call: edit_file, retry.\nTool call: write_file, ok.\nTool call: edit_file, retry.\nTool call: edit_file, retry.\n\xe2\x9c\x93 Took 0 item(s) to a ready pull request, stopped 1.\nElapsed: 3m 53s\n'
    
  13. added a commit that references this issue on Oct 31, 2026
  14. dan-petty commented on Oct 31, 2026

    @dan-petty
    OwnerAuthor

    implement: retry

  15. added
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Oct 31, 2026
  16. devops-cli-service commented on Oct 31, 2026

    @devops-cli-service
    Contributor

    Pull request #2896 is ready for review. The checks passed.

    Spend: 46 model requests, 1500262 input tokens, 5112 output tokens.

  17. removed
    status/in-review
    on Oct 31, 2026
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

    effort/lowpriority/p1-highscope/securitysource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions