Skip to content

Path confinement test gaps: output refusal for most writing tools, and the roots fail-closed branch #398

Backlog

Description

@TMHSDigital

Summary

Input paths are confined centrally and covered by a registry test, but output paths are confined per tool, and only 4 of about 42 writing tools have an end-to-end test that refuses an output outside the client roots. The fail-closed branch in roots.ts (a client whose roots/list errors) is never exercised.

Where

  • src/utils/argPaths.ts:20-24
  • src/server.ts:178-198
  • src/__tests__/argPathsCoverage.test.ts:37-54
  • src/__tests__/roots.test.ts:129-156
  • src/tools/translateSubtitles.ts:51-60
  • src/tools/addMarker.ts:61
  • src/utils/roots.ts:39-47
  • src/__tests__/roots.test.ts:97-113

Details

Input paths are confined centrally. The registerTool wrapper (server.ts:186-191) calls assertArgPaths on every call, and argPathsCoverage.test.ts makes sure every path-like field is classified. Output fields are not confined centrally. argPaths.ts:20-24: "Paths the server writes: only the network check here; the tools confine them through resolveOutput/assertOutputAllowed." So each tool's handler is the only control on output/outputDir. 43 tool files declare one of those fields. End-to-end refusal of an output outside the client roots is asserted for four of them: trim (roots.test.ts:139-150), bug_report, index_recording and step_guide (integration tests). argPathsCoverage passes as soon as output is in LOCAL_ONLY_KEYS, whether or not the handler confines it. Two tools hand-roll the check instead of going through editOutput: translate_subtitles (assertOutputAllowed(output) and assertOverwriteAllowed at translateSubtitles.ts:55-58) and add_marker (addMarker.ts:61). Their write paths are never exercised. The toolLayer case at toolLayer.test.ts:117 calls translate_subtitles without translations, so lines 51-63 (write, overwrite refusal, confinement) stay uncovered.

Also: roots.ts fail-closed branch (listRoots error) is never exercised

A client that advertises roots but fails roots/list must fail closed. On the initial read, setClientRoots([]) confines outputs to SCREENCAST_HOME and the allowed dirs. On a refresh, the previous roots are kept. The per-line coverage run shows lines 45-46 with 0 hits and the if (initial) branch uncovered on both sides. roots.test.ts covers setClientRoots directly (97-113) and the happy-path listRoots/list_changed flow (129-156), but never a client whose ListRoots handler throws.

} catch (err) {
  // A client that advertises roots but cannot list them fails closed
  if (initial) setClientRoots([]);
  process.stderr.write(`roots/list failed: ${errorMessage(err)}\n`);
}

Steps: Change roots.ts:45 to setClientRoots(null) and run npx vitest run src/__tests__/roots.test.ts. It passes.

Impact

If a tool drops or reorders its editOutput/assertOutputAllowed call, or a new tool writes args.output directly, the server writes outside the client's roots and no test fails.

Steps to reproduce

Remove assertOutputAllowed(output); from src/tools/translateSubtitles.ts:55 and run npx vitest run. The suite stays green.

Suggested fix

Add one sweep test in the style of argPathsCoverage. Connect a client with roots [project], then for every listed tool whose inputSchema has output or outputDir, call it with the minimal valid fixture args from toolLayer's CASES and output set to a path in a non-root temp dir. Assert isError with /outside the allowed directories/, and that no file appeared there. Keep an explicit allowlist with a reason for each tool that cannot run on a fixture. Also add translate_subtitles handler cases: translations without language is refused, a non-.srt output is refused, an existing output without overwrite is refused, an output outside roots is refused, and a successful write keeps the cue timings.

For "roots.ts fail-closed branch (listRoots error) is never exercised": In roots.test.ts, add (1) a client with capabilities: { roots: {} } whose ListRoots handler throws: getClientRoots() settles to [], and a trim with an output outside SCREENCAST_HOME is refused. (2) A first list that succeeds with [project], then a list_changed whose handler throws: roots stay [project]. (3) A client without the roots capability: getClientRoots() is null. (4) rootDirs with a malformed file: URI is skipped (line 22).

Acceptance criteria

  • A table-driven test calls every tool that takes output/outputDir with a path outside the roots and expects a refusal
  • Tests for a client whose roots/list throws: initial read confines to SCREENCAST_HOME, and a refresh keeps the previous roots

Getting started

  • Relevant files: src/utils/argPaths.ts, src/server.ts, src/__tests__/argPathsCoverage.test.ts, src/__tests__/roots.test.ts
  • Run tests: npm test (also npm run typecheck and npm run lint); see CONTRIBUTING.md
  • If you change a tool's schema or description, run npm run docs

Filed by repo-audit/full-audit at f0e5ebd. Severity: medium. Effort: M. audit-key: testing|src/utils/argPaths.ts|LOCAL_ONLY_KEYS

Activity

  1. added
    help wanted
    testing
    effort: medium
    on Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort: mediumhelp wantedpriority: mediumtesting

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions