diff options
| author | Mohamed Hegazy <mhegazy@anthropic.com> | 2026-10-14 16:31:13 +0000 |
|---|---|---|
| committer | Claude <noreply@anthropic.com> | 2026-10-19 16:29:25 +0000 |
| commit | f5ce0a810148d3d86cd7ac99b007289fd8e3fb15 (patch) | |
| tree | 45bc0a333e24bd40da6978ac9a0f1c188c2e96c6 /plugins/security-guidance/hooks/diffstate.py | |
| parent | ea10b213686c90bb1984b2016937310e05336cf3 (diff) | |
security-guidance: find a rewritten file's earlier version from a repo subdirectory
A full-file Write is checked against the file as it was at the start of the turn, so risky calls that were already there are not reported as new. The lookup passed git a path relative to the session directory, which git reads from the repo root, so it failed for any session started below the root, and on Windows for any path with a separator. Ask for ./<path> with forward slashes.
Fixes #5684
Diffstat (limited to 'plugins/security-guidance/hooks/diffstate.py')
| -rw-r--r-- | plugins/security-guidance/hooks/diffstate.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/plugins/security-guidance/hooks/diffstate.py b/plugins/security-guidance/hooks/diffstate.py index f2d9dbe4..557c3825 100644 --- a/plugins/security-guidance/hooks/diffstate.py +++ b/plugins/security-guidance/hooks/diffstate.py @@ -175,8 +175,13 @@ def get_baseline_file_content(session_id, file_path, cwd): rel_path = os.path.relpath(abs_path, cwd_abs) except ValueError: return None + # `<rev>:<path>` is read from the repo root unless the path starts + # with `./`, and takes forward slashes only. Without both, the lookup + # fails for a session started below the repo root, and on Windows for + # any file that is not directly in the session directory. + rel_path = rel_path.replace(os.sep, "/") result = subprocess.run( - [*GIT_CMD, "show", f"{baseline_sha}:{rel_path}"], + [*GIT_CMD, "show", f"{baseline_sha}:./{rel_path}"], cwd=cwd, capture_output=True, timeout=5 ) if result.returncode == 0: |
