test_a_hostile_name_cannot_escape_the_state_directory¶
Tests › tests/test_named_targets.py
What this test is for
Why it exists
THE NAME REACHES A FILESYSTEM PATH, so it is untrusted input to a path join. A name of `../../etc` would otherwise place a database outside the state root — and sub-index names come from a repository's own `.clew.yaml`, which is exactly the "target repo influences the build" surface this project keeps hardening.
Given
repo = tmp_path / "myproj"repo.mkdir()state = (tmp_path / "state").resolve()
When
for hostile in ("../../etc", "..", "a/b", "with space", "sub\x00idx"): try: got = target_for(repo, state, name=hostile) except (ValueError, OSError): continue resolved = Path(got.db_path).resolve() assert resolved.is_relative_to(state), ( f"name {hostile!r} placed a database outside the state root: {resolved}" )
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.
thread `clew-first-build-` — `_first_build_worker` (clew/mcp_server/server.py) · 2 of 142 steps
… 31 earlier steps
… 105 later steps
4 more
- Build, refresh and check the index · 2 of 153 steps
- clew — `main` (clew/cli.py) · 2 of 400 steps
- clew-mcp — `main` (clew/mcp_server/server.py) · 2 of 17 steps
- `main` (scripts/incremental_probe.py) · 2 of 3 steps
tests/test_named_targets.py:117 · its file's page
What it checks (1)
assert resolved.is_relative_to(state), ( f"name {hostile!r} placed a database outside the state root: {resolved}" )not attributed
Where the product reaches it
main→query_main→_locate→target_for(flow)
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.
Also reaches 1 requirement
Its run touches their code; that is reach, not proof.
- REQ-DDB-MCP-001 measured