Skip to content

fix(mcp): jail LLM source-excerpt reads to the project root - #153

Merged
tachyon-beep merged 1 commit into
release/1.6.0from
fix/mcp-source-excerpt-jail
Sep 1, 2026
Merged

fix(mcp): jail LLM source-excerpt reads to the project root#153
tachyon-beep merged 1 commit into
release/1.6.0from
fix/mcp-source-excerpt-jail

Conversation

@tachyon-beep

Copy link
Copy Markdown
Collaborator

Rebase of #151 (Codex) onto release/1.6.0, the working release branch. Same single commit.

What

verified_source_excerpt read entity.source_file_path straight from the catalogue row. A poisoned (committed) index could therefore name any local file and have its contents folded into a live LLM prompt (summary, inferred-calls). The read is now revalidated at use time with the existing storage normalize_source_path (lexical + canonical containment in the project root); escapes fail closed with the existing invalid-path envelope and never reach the provider.

Review notes

  • SourceExcerptError becomes an enum (ContentDrift | InvalidPath); envelopes and inferred-dispatch failures map codes accordingly.
  • Regression: summary_cold_miss_refuses_catalogue_path_outside_project (provider sees zero invocations).
  • cargo fmt --check, clippy -D warnings (loomweave-mcp), nextest -p loomweave-mcp (512) green.

Supersedes #151.

🤖 Generated with Claude Code

Copilot AI lite review requested due to automatic review settings September 1, 2026 19:14
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens loomweave-mcp against catalogue/index poisoning by re-validating EntityRow.source_file_path at read time so LLM source-excerpt reads cannot escape the project root, and it adds a regression test to ensure the provider is not invoked on invalid paths.

Changes:

  • Revalidates source excerpt paths against the canonical project root via normalize_source_path, failing closed with invalid-path.
  • Refactors SourceExcerptError into an enum and maps envelope/inferred-dispatch errors to the correct McpErrorCode.
  • Adds a regression test that poisons entities.source_file_path with an outside-project path and asserts the provider is never called.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
crates/loomweave-mcp/src/lib.rs Adds project-root–jailed path normalization to verified_source_excerpt and updates error typing/mapping.
crates/loomweave-mcp/src/tools/summary.rs Plumbs project root into excerpt verification for summary + inferred-call prompt paths.
crates/loomweave-mcp/src/tools/status.rs Uses the new jailed excerpt verification when estimating input tokens on cache misses.
crates/loomweave-mcp/tests/storage_tools.rs Adds regression test covering outside-project source_file_path poisoning and provider non-invocation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +6180 to +6186
// Catalogue rows are untrusted and may be committed with the project. Jail
// every read at use time; canonicalization also rejects symlinks escaping
// the project root.
let path =
normalize_source_path(project_root, path).map_err(|_| SourceExcerptError::InvalidPath {
entity_id: entity.id.clone(),
})?;
@tachyon-beep
tachyon-beep merged commit c70ed12 into release/1.6.0 Sep 1, 2026
6 checks passed
@tachyon-beep
tachyon-beep deleted the fix/mcp-source-excerpt-jail branch September 1, 2026 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants