test_read_body_refuses_paths_escaping_repo_root¶
Tests › tests/test_query.py
What this test is for
Why it exists
#39 defense-in-depth: R3 serves whatever db a caller points it at, so a tampered/foreign db could record an absolute (`/etc/passwd`) or `../`-escaping body path — which `root / file` would happily follow OUTSIDE the working tree, turning `source` into an arbitrary-file read. The escape target here EXISTS and is readable, so a None result proves the containment check (not an OSError fallback) is what refuses it; the contained control reads normally.
Verifies REQ-DDB-QUERY-001 REQ-DDB-QUERY-002
Given
root = tmp_path / "repo"root.mkdir()
3 more
(root / "src.c").write_text("line1\nline2\n", encoding="utf-8")outside = tmp_path / "secret.txt"outside.write_text("TOP SECRET\n", encoding="utf-8")
When
ok = _read_body(root, "src.c", 1, 2, 10)_read_body(root, str(outside), 1, 1, 10)_read_body(root, "../secret.txt", 1, 1, 10)
Then
- ✓ ok is not None
- ✓ ok[0] equals ["line1", "line2"]
- ✓ _read_body(root, str(outside), 1, 1, 10) is None
- ✓ _read_body(root, "../secret.txt", 1, 1, 10) is None
tests/test_query.py:746 · its file's page
What it checks (3)
assert ok is not None and ok[0] == ["line1", "line2"]observes_read_bodyviaokassert _read_body(root, str(outside), 1, 1, 10) is Noneobserves_read_bodyassert _read_body(root, "../secret.txt", 1, 1, 10) is Noneobserves_read_body
Where the product reaches it
No product flow reaches this code: no product entry point's flow calls any of the functions this test calls.
Call flow
test_read_body_refuses_paths_escaping_repo_root→_read_bodyWhat it reaches
Each row runs from this test, through the calls it makes, to the code a requirement names. If that code breaks, the test's checks are what should catch it. Reaching is not proving: a check only proves what it observes. No mutation records were given, so these rows say what the test REACHES.
Requirements it verifies (2)
| requirement | linked by | implementers exercised |
|---|---|---|
| REQ-DDB-QUERY-001 | catalog | unknown |
| REQ-DDB-QUERY-002 | catalog | unknown |