test_a_declared_root_outside_the_repository_is_refused

Tests › tests/test_kconfig.py

passed Passed in the packaged run.

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

  1. outside = tmp_path / "outside"
  2. outside.mkdir(exist_ok=True)
  3. (outside / KCONFIG_NAME).write_text("config LEAKED\n\tbool\n", encoding="utf-8")
→

When

  1. 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

  1. —

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

  1. root = tmp_path / "repo"
  2. (root / "src").mkdir(parents=True)
2 more
  1. outside = tmp_path / "outside"
  2. (outside / "secrets").mkdir(parents=True)
→

When

  1. 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

  1. —

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

command-line usercommand-line usercommand-line usercommand-line userclew/scope.pyclew/scope.pyclew/scope.pyclew/scope.pyother filesother filesother filesother filesalt (line 1171)altopt (line 529)optmain11. propose → build_context11build_context12. build_context → derive_scope12derive_scope13. derive_scope → _declared_index_scope13_declared_index_scope▶ test enters14. _declared_index_scope → load_declaration_located14load_declaration_located15–18. load_declaration_located → _read_mapping15_read_mapping +3 more19–20. _checked_section → _checked_list_section19_checked_list_section +1 more

… 18 steps between

command-line usercommand-line usercommand-line usercommand-line usercommand-line userclew/scope.pyclew/scope.pyclew/scope.pyclew/scope.pyclew/scope.pyother filesother filesother filesother filesother filesloop (line 598)loopopt (line 696)opttry (line 1003)tryopt (line 847)optloop (line 746)looploop (line 1055)loopopt (line 1075)optmain39–40. _checked_document → _checked_entries39_checked_entries +1 more41. _checked_section → _check_section_keys41_check_section_keys42–43. _declared_index_scope → _existing_paths42_existing_paths +1 more44. _declared_index_scope → _existing_paths44_existing_paths45. derive_scope → whole_repo_scope45whole_repo_scope▶ test enters46. whole_repo_scope → _gitignored_paths46_gitignored_paths47. _gitignored_paths → git_argv47git_argv48–49. git_argv → _no_ext_diff48_no_ext_diff +1 more50. _gitignored_paths → git_env50git_env51. whole_repo_scope → list51list52–56. whole_repo_scope → nested_repo_roots52nested_repo_roots +4 more57. nested_repo_roots → _nested_repos_under57_nested_repos_under58. whole_repo_scope → _gitignored_paths58_gitignored_paths59–60. whole_repo_scope → _pruned_dirs59_pruned_dirs +1 more61. _pruned_dirs → _skip_dir61_skip_dir62–64. _pruned_dirs → _descendable62_descendable +2 more65–68. whole_repo_scope → _declaration_note65_declaration_note +3 more69. derive_scope → whole_repo_scope69whole_repo_scope70. build_context → repo_source_files70repo_source_files

… 330 later steps

4 more

tests/test_kconfig.py:1193 · its file's page

What it checks (2)

  1. assert location.path is None, ( f"{declared!r} escapes the repository and must not be parsed; got {location.path}" ) observes discover_kconfig via location
  2. assert location.source != SOURCE_DECLARED, ( "a refused declaration must not be recorded as the honoured source" ) observes discover_kconfig via location

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_a_declared_root_outside_the_repository_is_refused→discover_kconfig

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.

test_a_declared_root_outside_the_repository_is_refused · 2 checksdiscover_kconfigREQ-DDB-CONFIG-005 · measureddiscover_kconfig_declared_kconfigwithin_repoREQ-DDB-PIPE-014 · measured

tests/test_scope.py:585 · its file's page

What it checks (3)

  1. assert rejection is not None, f"{entry!r} escapes the repository and must be rejected" observes declared_scope_rejection via rejection
  2. 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" ) observes all
  3. 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" ) observes declared_scope_rejection

Where the product reaches it

  • main → propose_main → propose → build_context → derive_scope → _declared_index_scope → _existing_paths → _is_within (flow)
  • dossier → _rank_enum_over_mirror → _class_side_is_only_enum_mirrors → all (flow)
  • main → propose_main → propose → build_context → derive_scope (flow)

Call flow

test_a_declared_root_outside_the_repository_is_refused→declared_scope_rejection→derive_scope→all→_is_within

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.

test_a_declared_root_outside_the_repository_is_refused · 3 checksdeclared_scope_rejectionREQ-DDB-CONFIG-001 · measureddeclared_scope_rejection… 5 calls …_validate_nodeREQ-DDB-GUARD-012 · inferredallREQ-DDB-WIKI-054 · inferred

Requirements it verifies (2)

requirementlinked byimplementers exercised
REQ-DDB-PIPE-007catalogunknown
REQ-DDB-QUERY-006catalogunknown
Also reaches 5 requirements

Its run touches their code; that is reach, not proof.