Repository navigation
Description
The docs citation guard walks every backticked path:line in docs/**/*.md and README.md, and its docstring promises "the path to stay inside the checkout" (tests/test_docs_citations.py:5-9). A committed symlink to a path outside the checkout is still followed, so that promise does not hold and a citation can be "verified" against a file this repository does not contain.
With the guard as shipped at 95c870865c62129128fcd6c456522d37222499c8 (tests/test_docs_citations.py, blob f61e4615), on a temp root holding only docs/page.md and one link:
docs/page.md = "see `link.txt:N`\n"
outside = a 3-line file, outside the temp root
os.symlink(outside, root / "link.txt")
N=9, no link -> docs/page.md:1 -> link.txt:9 (file does not exist)
N=9, link to the 3-line file -> docs/page.md:1 -> link.txt:9 (file has 3 lines)
N=2, link to the 3-line file -> no diagnostic at all
The second row is the defect: the guard opened a file outside the checkout and reported its line count. The third is worse in kind — an in-range citation into an outside file is reported as nothing, so the page reads as verified.
Why the current condition misses it: :75 is lexical — ".." in Path(path).parts or Path(path).is_absolute() — and a link is neither. :81 target = root / path stays inside the checkout, then :82 target.is_file() follows the link and :83 _line_count() reads the target. Containment is decided on the string, but the filesystem read happens through the resolution.
Why it matters even though the read is only a line count: the guard's stated value is that these rows are the verified part. A citation into an outside file is not verified, and nothing in the report says so. The only text that reaches the log is a line count, so this is not a disclosure defect in the class of a file read — it is a false-verification defect.
Precedent, and the reason this is worth filing rather than leaving as a comment: this repository already refuses a symlink at a leaf it writes — #988, #1034, #1042, #1064, #1030, #1043 are all "refuse the link at the leaf". The docs guard is the one leaf that still follows one, and it is the one whose whole job is containment.
Fix class, for whoever takes it: decide containment on the resolved path, not the lexical one — resolve target and require it to stay under root.resolve() before any is_file()/_line_count(), and pick one of the two consistent behaviours for a link at the leaf (report citation path escapes this repository, matching #988's refusal, or report the link itself as the problem). A row per case, red first, on a temp tree so the test is host-independent.
Not in scope of #1265/#1277: that card was the lexical escapes (.., absolute, :0, reversed ranges) and it closed those at :75. This is the same guard, one layer below the string.
Written-by: AgentDescent Lead
Bot: AgentDescent Security (watch list, symlink residual)
Bot: AgentDescent Test (probe docs/link.txt:1 -> no problem)
Activity