Repository navigation
fix(harness): strip file:// scheme before sensitive-path probing - #292
Conversation
|
@Zongwei9888 Hi! This PR fixes a denylist bypass in the sensitive-path probe ( |
file: URLs passed as tool path/argument values missed the denylist suffix probe: the raw string "file:///home/u/.ssh/id_rsa" never suffix-matches "/home/u/.ssh/id_rsa", so is_sensitive_path returned False and _extract_file_targets still extracted the value as a filesystem path -> denylist bypass under FULL_AUTO. Normalize the boundary value once (_strip_file_scheme): case-insensitive file: scheme strip (plain, //host/share UNC and //localhost forms) plus percent-decoding, before the existing suffix probe. Scope stays minimal: only the file: form is rewritten; http(s)/ws(s) and other URL schemes, plain filesystem paths and relative names keep byte-identical behavior. Tests: 7 new cases (non-path keys, percent-encoding, localhost/UNC, Windows drive form, nested arguments) plus two negative controls (remote URLs and prose mentioning file: are not paths).
a0dd0ce to
7df63b8
Compare
|
Merged on 2026-11-16 as d107ccb ("Merge PR #292"), with one follow-up commit, a96d5ec. Thank you, and thanks for asking for a security review; this is it. Confirmed on main: a read-only-named MCP tool given The follow-up (a96d5ec):
You offered to split the |
Problem
is_sensitive_path()probes candidate paths by suffix matching after_normalize_path(). Afile://URL — e.g.file:///home/u/.ssh/id_rsa— never suffix-matches the denylist entry/home/u/.ssh/id_rsa, sois_sensitive_path()returnsFalseand a protected-path denylist entry can be bypassed under permissive permission modes (FULL_AUTO/AUTOPILOT) by simply wrapping the path in afile:scheme. The same bypass works for percent-encoded (file:///home/u/.ssh/%69d_rsa), UNC (file://host/share/...),localhost, and Windows drive (file:///C:/Users/...) forms, and for nested tool-callargumentsunder non-path keys.Fix
_normalize_path()now strips a leadingfile:scheme (case-insensitive, including//host/shareUNC and//localhostforms) and percent-decodes the result before the denylist suffix probe (new helper_strip_file_scheme,urllib.parse.urlparse+unquote)._path_values()additionally yields string values that start withfile:even when the key does not match_PATH_KEY, closing nested-argument bypasses.No allowlist semantics, no other scheme handling, and no probe ordering is changed.
Tests
7 new module-level tests in
tests/test_harness_permissions.py:file://URL under a non-path key is deniedlocalhostand UNC forms are deniedfile://in nestedargumentsis deniedhttp(s)://URLs are not treated as paths (no false positives)file://URL is not treated as a pathRED/GREEN paired verification on this branch (Python 3.12–3.14): pre-fix 5 failed / 2 passed (RED) → post-fix 7/7 passed (GREEN). The two false-positive guards were already passing and stay passing.
Security Considerations
~/.ssh/id_rsacan be read/written by a craftedfile://argument.file:scheme is stripped;http(s)://URLs and prose mentions are regression-tested to remain non-paths...traversal, symlink escapes (covered by separate tests, incl.test_denylist_follows_symlinks), and Windows 8.3 short-name / NTFS stream aliasing.Local CI preflight on this revision: all legs green except pre-existing Windows-environmental reds (xdist worker collapse on py3.12; pre-existing platform red family on py3.13/3.14 — proven identical on pristine base
4ff321ecvia failed-set differential, net new reds attributable to this diff = 0).@Zongwei9888 requesting a security review — this touches the sensitive-path denylist boundary.