fix(agent): scope subdirectory hint discovery to active workspace boundary - #14795
fix(agent): scope subdirectory hint discovery to active workspace boundary#14795Tranquil-Flow wants to merge 1 commit into
Conversation
b027e84 to
8ae2a17
Compare
8ae2a17 to
4056d14
Compare
egilewski
left a comment
There was a problem hiding this comment.
requesting changes
The PR widens the boundary from the active working_dir to the containing git root, which leaves a residual prompt-injection path when Hermes is operating from a subdirectory inside a larger repository. In that setup, a tool call touching a sibling directory under the same git root can still load that sibling's AGENTS.md into the agent context.
I reproduced this with a synthetic git repo containing workspace/ as the active working_dir and sibling/AGENTS.md outside that active workspace. Loading agent/subdirectory_hints.py from current main returned None, but loading the PR head returned:
pr_head: loaded_sibling_hint=True result='... [Subdirectory context discovered: .../sibling/AGENTS.md]\nSIBLING INSTRUCTIONS'
The cause is that PR head sets _workspace_root to git rev-parse --show-toplevel when available (SubdirectoryHintTracker.__init__), and _add_path_candidate() only checks paths against that git root. The PR tests pass, but they do not create a git repository around a nested working directory, so they only exercise the fallback where _workspace_root == working_dir.
Security evidence:
- trust boundary: post-tool-call discovery of
AGENTS.md/CLAUDE.md/.cursorrulesfrom tool path arguments. - source/sink/invariant: untrusted tool path argument to appended subdirectory context; invariant should be no hint files outside the active workspace/working directory.
- current-main reproduction: current main
03d9a95a74b234c2d46e0b59cf6e12281f93fbf5blocked the sibling hint in the synthetic nested-workspace repo. - PR-head validation: PR head
4056d141ddedc0e340a1e5f56c4d24c410113e24loaded the siblingAGENTS.md. - positive/negative cases: PR's own focused tests passed (
26 passed), but the missing nested-git-root negative case reproduces the bypass. - residual bypass search: sibling directory under same git root but outside active
working_dir. - reviewer-tool status: skipped because local review already found a decisive security bypass.
Signed: GPT-5.5-xhigh in Codex
|
This is an automated hermes-sweeper review. Current main already implements the security boundary this PR was aiming for. Evidence:
I also ran a small synthetic nested-workspace check against current HEAD: a sibling |
What does this PR do?
Post-tool-call path discovery scanned any directory for
AGENTS.md,CLAUDE.md, and.cursorrulesfiles, even those outside the intended workspace. A tool call touching a file elsewhere on disk could silently inject unrelated instruction files into the agent context, causing unexpected behavior drift and cross-project leakage.Related Issue
Fixes #14471
Type of Change
Changes Made
agent/subdirectory_hints.py: Scoped discovery to active workspace boundarytests/agent/test_subdirectory_hints.py: 26 testsHow to Test
python -m pytest -o 'addopts=' tests/agent/test_subdirectory_hints.py -vResult: 26 passed.
Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs