Skip to content

test(security): tests make the subprocess environment guard and the review target guard refuse unsafe input - #2206

Merged
dan-petty merged 1 commit into
mainfrom
test/2151-guards-refuse-unsafe-input
Oct 25, 2026
Merged

dan-petty merged 1 commit into
mainfrom
test/2151-guards-refuse-unsafe-input

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

Summary

Two security guards had no test that made them refuse their input, so a change that removed a guard passed the suite. This pull request adds those tests and deletes two checks that no input reaches.

  • tests/test_subprocess_env_boundary.py: build_subprocess_env(env=...) gets each of the six refused keys (LD_PRELOAD, LD_LIBRARY_PATH, DYLD_INSERT_LIBRARIES, DYLD_LIBRARY_PATH, BASH_ENV, ENV), in upper and in lower case, and a null byte in a key and in a value. Each case runs with isolation on and off. Each case raises SecurityError, and the test checks the message that names the key, the exit code and the error code.
  • tests/review/test_review_targets_stay_inside_the_repository.py: the tests build a repository and a tree beside it under tmp_path, with real files and symlinks. A target outside the root raises SecurityError: a directory, a file, a path through .., a symlink to a file and a symlink to a directory. A symlinked target file gives []. A directory target leaves out each symlink that it holds, to a file outside or inside the root. A file that the pattern */*.py reaches through a symlinked directory is no symlink, and only the real-path check leaves it out; the test asserts that rglob gives that file first.
  • src/devops_cli/review/targets.py: the second condition of the symlink check of a target file (not target_resolved.is_relative_to(root)) is deleted. The function already raised for that target. The try/except OSError, RuntimeError around the real-path check of a candidate is also deleted. On Python 3.14, posixpath.realpath ignores every OSError when strict is false, and a check of Path.resolve() on a symlink loop and below a directory with mode 000 raised nothing. find_repo_files resolves the target first, so os.getcwd() fails there first for a relative target. docs/TESTING.md says that a line no public behavior reaches is deleted.

The tests start no program, patch no devops_cli name and read no host state. They pass on the stock path of a GitHub runner (env PATH=/usr/bin:/bin .venv/bin/python -m pytest ...: 76 passed).

The new tests pass on the base, because the guards are there. To show that each test holds its guard, a scratch copy of the base 527558fa had each guard removed in turn:

Guard removed Result
refused-key check 24 failed
refused-key check made case-sensitive 12 failed, 12 passed
null-byte check 4 failed
null-byte check of the key only 2 failed, 2 passed
null-byte check of the value only 2 failed, 2 passed
outside-root error of find_repo_files 5 failed
symlink check of a target file 1 failed
symlink check of a candidate 1 failed
real-path check of a candidate 1 failed

Item

Closes #2151

Change: openspec/changes/archive/2026-10-25-2151-guards-refuse-unsafe-input/

…eview target guard refuse unsafe input

Tests make build_subprocess_env refuse each of the six loader and shell
start-up keys, in upper and lower case, and a null byte in a key and in a
value. Tests make find_repo_files refuse a target outside the repository
root, give no files for a symlinked target file, and leave out the
symlinks and the files below a symlinked directory. Each test fails when
its guard is removed.

Delete the unreachable second condition of the symlink check of a target
file, and the unreachable except of the real-path check of a candidate.

Closes #2151
@dan-petty
dan-petty marked this pull request as ready for review October 25, 2026 00:21
@dan-petty
dan-petty merged commit 48cb34a into main Oct 25, 2026
17 checks passed
@dan-petty
dan-petty deleted the test/2151-guards-refuse-unsafe-input branch October 25, 2026 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(security): tests make the subprocess environment guard and the review target guard refuse unsafe input

1 participant