test_a_declared_root_outside_the_repository_is_refused¶
Tests › tests/test_kconfig.py
What this test is for
Why it exists
H4, 1.1.0 SECURITY AUDIT. `kconfig.root` is repo-relative by contract and nothing enforced it: `(root / declared).resolve()` honours an absolute entry and `../` walks out. Two consequences, both reachable by an MCP caller who STATES the section for a repository it merely names. First, arbitrary read — a Kconfig anywhere on the machine is parsed and its `help` text, prompts and defaults are served as this repository's configuration space. Second, it is a route around every other containment here: kconfiglib resolves `source` against `$srctree`, and the outside file chooses what gets sourced.
Verifies REQ-DDB-PIPE-007 REQ-DDB-QUERY-006
Given
outside = tmp_path / "outside"outside.mkdir(exist_ok=True)(outside / KCONFIG_NAME).write_text("config LEAKED\n\tbool\n", encoding="utf-8")
When
for declared in (str(outside / KCONFIG_NAME), "../outside/Kconfig"): location = discover_kconfig(repo, {SECTION_KCONFIG: {KEY_ROOT: declared}}) assert location.path is None, ( f"{declared!r} escapes the repository and must not be parsed; got {location.path}" ) assert location.source != SOURCE_DECLARED, ( "a refused declaration must not be recorded as the honoured source" )
Then
- —
What this test is for
Why it exists
H5, 1.1.0 SECURITY AUDIT. `roots:` is repo-relative by contract, but the derivation resolved each entry with `(root / entry).resolve()` and asked only whether it EXISTS. An absolute entry discards `root` entirely (`Path('/a') / '/etc'` is `/etc`), and `../` walks out, so a repository — or an MCP caller stating a scope for a repository it merely names — chose any readable directory on the machine as the indexed tree. The index is then served as that repository's content, with the paths of a tree the owner never offered.
Verifies REQ-DDB-PIPE-007 REQ-DDB-QUERY-006
Given
root = tmp_path / "repo"(root / "src").mkdir(parents=True)
2 more
outside = tmp_path / "outside"(outside / "secrets").mkdir(parents=True)
When
for entry in (str(outside), "../outside", "src/../../outside"): (root / ".clew.yaml").write_text( f"index_scope:\n roots:\n - {entry}\n", encoding="utf-8" ) rejection = sc.declared_scope_rejection(root) derived = sc.derive_scope(root) assert rejection is not None, f"{entry!r} escapes the repository and must be rejected" assert all(sc._is_within(got, root.resolve()) for got in derived.roots), ( f"{entry!r} put {derived.roots} outside {root} — the index would carry a tree " f"this repository never offered" ) ## AND THE TIER-1 STATED FORM, which is the reachable half: an MCP caller states a ## scope for a repository it merely NAMES, so this entry never passed an owner's hands ## at all. Both tiers go through one derivation, which is why one fix covers both — ## asserted rather than assumed, since the replay path (`_replay_manifest_statements`) ## re-enters the same function on every later build. stated = {"roots": [entry]} assert sc.declared_scope_rejection(root, stated) is not None, ( f"a STATED root of {entry!r} must be rejected exactly as a declared one is" )
Then
- —
What it exercises
The parts of the system's flows this test ran, measured by per-test coverage: lit steps ran in this test, dimmed ones did not, and ▶ marks where the test called in. Each title opens the whole flow with these steps lit.
clew — `main` (clew/cli.py) · 30 of 400 steps
… 10 earlier steps
… 18 steps between
… 330 later steps
4 more
- thread `clew-first-build-` — `_first_build_worker` (clew/mcp_server/server.py) · 29 of 142 steps
- Build, refresh and check the index · 20 of 153 steps
- Build this wiki from the index · 7 of 400 steps
- `main` (clew/guard/main.py) · 2 of 357 steps
tests/test_kconfig.py:1193 · its file's page
What it checks (2)
assert location.path is None, ( f"{declared!r} escapes the repository and must not be parsed; got {location.path}" )observesdiscover_kconfigvialocationassert location.source != SOURCE_DECLARED, ( "a refused declaration must not be recorded as the honoured source" )observesdiscover_kconfigvialocation
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
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.
tests/test_scope.py:585 · its file's page
What it checks (3)
assert rejection is not None, f"{entry!r} escapes the repository and must be rejected"observesdeclared_scope_rejectionviarejectionassert all(sc._is_within(got, root.resolve()) for got in derived.roots), ( f"{entry!r} put {derived.roots} outside {root} — the index would carry a tree " f"this repository never offered" )observesallassert sc.declared_scope_rejection(root, stated) is not None, ( f"a STATED root of {entry!r} must be rejected exactly as a declared one is" )observesdeclared_scope_rejection
Where the product reaches it
Call flow
test_a_declared_root_outside_the_repository_is_refused→declared_scope_rejection→derive_scope→all→_is_withinWhat 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-PIPE-007 | catalog | unknown |
| REQ-DDB-QUERY-006 | catalog | unknown |
Also reaches 5 requirements
Its run touches their code; that is reach, not proof.
- REQ-DDB-CONFIG-001 measured
- REQ-DDB-CONFIG-005 measured
- REQ-DDB-GUARD-012 inferred
- REQ-DDB-PIPE-014 measured
- REQ-DDB-WIKI-054 inferred