Skip to content

🛡️ Sentinel: [CRITICAL/HIGH] Fix path traversal in module resolution#293

Open
bashandbone wants to merge 1 commit into
mainfrom
sentinel-fix-path-traversal-6371263555837495802
Open

🛡️ Sentinel: [CRITICAL/HIGH] Fix path traversal in module resolution#293
bashandbone wants to merge 1 commit into
mainfrom
sentinel-fix-path-traversal-6371263555837495802

Conversation

@bashandbone

@bashandbone bashandbone commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

🚨 Severity: HIGH
💡 Vulnerability: During manual canonicalization in the TypeScript dependency extractor (crates/flow/src/incremental/extractors/typescript.rs), popping std::path::Component::ParentDir could incorrectly traverse beyond restricted directory boundaries (like RootDir or Prefix) when canonicalize failed, or misinterpret valid relative paths like ../../a.
🎯 Impact: Attackers might be able to exploit module specifiers to escape project roots or load malicious local modules, bypassing module resolution constraints.
🔧 Fix: Explicitly track bounds during path normalizations. Added safeguards so that ParentDir pushes instead of drops when the stack is empty or contains another ParentDir, preserving relative patterns, and ignores root/prefix overrides.
✅ Verification: Tested against standard TS resolution behavior using cargo test -p thread-flow --test extractor_typescript_tests and verified the logic handles complex paths. Documented the pattern strictly inside the Sentinel journal at .jules/sentinel.md.


PR created automatically by Jules for task 6371263555837495802 started by @bashandbone

Summary by Sourcery

Harden TypeScript module path normalization to prevent path traversal and document the vulnerability in the Sentinel journal.

Bug Fixes:

  • Prevent path traversal in the TypeScript dependency extractor by bounding how parent directory components are applied during manual path resolution.

Enhancements:

  • Simplify several Rust APIs by removing unnecessary lifetime parameters and minorly improving readability in string handling and rule definitions.

Documentation:

  • Add Sentinel journal entry describing the TypeScript extractor path traversal vulnerability, its root cause, and the mitigation.

Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings June 6, 2026 17:59
@sourcery-ai

sourcery-ai Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Fixes a HIGH-severity path traversal bug in the TypeScript dependency extractor’s manual path normalization, and includes a few minor refactors/formatting adjustments plus a Sentinel journal entry documenting the vulnerability and mitigation pattern.

File-Level Changes

Change Details Files
Harden manual path normalization in the TypeScript dependency extractor to prevent directory traversal when handling .. components.
  • Change handling of std::path::Component::ParentDir to inspect the last component before popping to avoid traversing past RootDir or Prefix boundaries.
  • When the stack is empty or the last component is ParentDir, push the new ParentDir instead of popping to preserve relative paths like ../../a.
  • Ignore pops when the last component is RootDir or Prefix, ensuring ParentDir cannot escape restricted roots during failed canonicalization.
crates/flow/src/incremental/extractors/typescript.rs
Apply small readability and API-simplification refactors in AST and rule engine code.
  • Inline the unwrap_or_else formatting for String::from_utf8 fallback logic in the tree-sitter content extension.
  • Reformat a long assert_eq! to a multi-line style for readability in tests.
  • Remove unnecessary lifetime parameters from check_var_in_constraints and check_var_in_transform and take references directly to simplify signatures.
  • Reformat Rule::Pattern branch’s defined_vars mapping to a multi-line chained iterator for consistency.
  • Simplify the Registration::read method by inlining the unwrap_or_else call into a single expression.
crates/ast-engine/src/tree_sitter/mod.rs
crates/rule-engine/src/check_var.rs
crates/rule-engine/src/rule/mod.rs
crates/rule-engine/src/rule/referent_rule.rs
Document the vulnerability and the hardened path-normalization pattern in the Sentinel journal.
  • Add a Sentinel entry describing the original path traversal issue in the TS extractor, its impact, and the reasoning behind the fix.
  • Record preventative guidelines for handling ParentDir, RootDir, and Prefix during manual path canonicalization to avoid similar bugs in the future.
.jules/sentinel.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In the TypeScript extractor path normalization, consider explicitly commenting what should happen for Windows-specific prefixes (e.g., UNC paths or verbatim prefixes) so future changes don’t accidentally alter the Prefix/ParentDir interaction you’re securing here.
  • The new ParentDir handling silently ignores upward traversal at a root/prefix boundary; if this represents an invalid or attack-like path, it might be safer to surface an error or signal (rather than silently normalizing) so callers can distinguish benign relative paths from blocked traversal attempts.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In the TypeScript extractor path normalization, consider explicitly commenting what should happen for Windows-specific prefixes (e.g., UNC paths or verbatim prefixes) so future changes don’t accidentally alter the `Prefix`/`ParentDir` interaction you’re securing here.
- The new `ParentDir` handling silently ignores upward traversal at a root/prefix boundary; if this represents an invalid or attack-like path, it might be safer to surface an error or signal (rather than silently normalizing) so callers can distinguish benign relative paths from blocked traversal attempts.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 the TypeScript/JavaScript dependency extractor’s manual path normalization to avoid unsafe .. handling when canonicalize() fails, addressing a potential path traversal vector during module resolution. It also includes small readability refactors in the rule engine and tree-sitter utilities, plus a Sentinel journal entry documenting the security issue.

Changes:

  • Harden Component::ParentDir normalization in TypeScriptDependencyExtractor::resolve_module_path to avoid popping past RootDir/Prefix and to preserve leading .. when appropriate.
  • Minor refactors for readability (method chaining formatting, lifetime elision, assertion formatting) across rule-engine and ast-engine.
  • Add a Sentinel journal entry describing the vulnerability and mitigation.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/rule-engine/src/rule/referent_rule.rs Minor formatting/refactor of lock-read + clone chain.
crates/rule-engine/src/rule/mod.rs Readability formatting for defined_vars() collection.
crates/rule-engine/src/check_var.rs Removes unnecessary explicit lifetimes in helper fns.
crates/flow/src/incremental/extractors/typescript.rs Security hardening for manual .. path normalization when canonicalization fails.
crates/ast-engine/src/tree_sitter/mod.rs Minor readability formatting for UTF-8 fallback and test assertion.
.jules/sentinel.md Adds Sentinel journal entry documenting the TS extractor path traversal issue and mitigation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .jules/sentinel.md
@@ -0,0 +1,4 @@
## 2024-06-06 - Path Traversal in TS Extractor
Comment on lines 808 to +824
for component in resolved.components() {
match component {
std::path::Component::ParentDir => {
components.pop();
// SECURITY: Prevent path traversal vulnerabilities by checking the last component
// before popping. We shouldn't pop RootDir or Prefix components.
// If the component list is empty or the last component is already ParentDir,
// we must push ParentDir to preserve relative paths like "../../a".
match components.last() {
Some(std::path::Component::RootDir)
| Some(std::path::Component::Prefix(_)) => {}
Some(std::path::Component::ParentDir) | None => {
components.push(component)
}
_ => {
components.pop();
}
}
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