fix(mcp): jail LLM source-excerpt reads to the project root - #153
Merged
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
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 withinvalid-path. - Refactors
SourceExcerptErrorinto an enum and maps envelope/inferred-dispatch errors to the correctMcpErrorCode. - Adds a regression test that poisons
entities.source_file_pathwith 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(), | ||
| })?; |
This was referenced Sep 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rebase of #151 (Codex) onto
release/1.6.0, the working release branch. Same single commit.What
verified_source_excerptreadentity.source_file_pathstraight 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 storagenormalize_source_path(lexical + canonical containment in the project root); escapes fail closed with the existinginvalid-pathenvelope and never reach the provider.Review notes
SourceExcerptErrorbecomes an enum (ContentDrift|InvalidPath); envelopes and inferred-dispatch failures map codes accordingly.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