Repository navigation
test(security): tests make the subprocess environment guard and the review target guard refuse unsafe input - #2206
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 raisesSecurityError, 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 undertmp_path, with real files and symlinks. A target outside the root raisesSecurityError: 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*/*.pyreaches through a symlinked directory is no symlink, and only the real-path check leaves it out; the test asserts thatrglobgives 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. Thetry/except OSError, RuntimeErroraround the real-path check of a candidate is also deleted. On Python 3.14,posixpath.realpathignores everyOSErrorwhenstrictis false, and a check ofPath.resolve()on a symlink loop and below a directory with mode000raised nothing.find_repo_filesresolves the target first, soos.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_cliname 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
527558fahad each guard removed in turn:find_repo_filesItem
Closes #2151
Change:
openspec/changes/archive/2026-10-25-2151-guards-refuse-unsafe-input/