test_read_body_refuses_paths_escaping_repo_root

Tests › tests/test_query.py

passed Passed in the packaged run.

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

  1. root = tmp_path / "repo"
  2. root.mkdir()
3 more
  1. (root / "src.c").write_text("line1\nline2\n", encoding="utf-8")
  2. outside = tmp_path / "secret.txt"
  3. outside.write_text("TOP SECRET\n", encoding="utf-8")
→

When

  1. ok = _read_body(root, "src.c", 1, 2, 10)
  2. _read_body(root, str(outside), 1, 1, 10)
  3. _read_body(root, "../secret.txt", 1, 1, 10)
→

Then

  1. ✓ ok is not None
  2. ✓ ok[0] equals ["line1", "line2"]
  3. ✓ _read_body(root, str(outside), 1, 1, 10) is None
  4. ✓ _read_body(root, "../secret.txt", 1, 1, 10) is None

tests/test_query.py:746 · its file's page

What it checks (3)

  1. assert ok is not None and ok[0] == ["line1", "line2"] observes _read_body via ok
  2. assert _read_body(root, str(outside), 1, 1, 10) is None observes _read_body
  3. assert _read_body(root, "../secret.txt", 1, 1, 10) is None observes _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_body

What 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)

requirementlinked byimplementers exercised
REQ-DDB-QUERY-001catalogunknown
REQ-DDB-QUERY-002catalogunknown