Skip to content

🛡️ Sentinel: [CRITICAL/HIGH] Fix path traversal in TypeScript extraction#304

Open
bashandbone wants to merge 1 commit into
mainfrom
sentinel/fix-path-traversal-typescript-extractor-13687102911898330852
Open

🛡️ Sentinel: [CRITICAL/HIGH] Fix path traversal in TypeScript extraction#304
bashandbone wants to merge 1 commit into
mainfrom
sentinel/fix-path-traversal-typescript-extractor-13687102911898330852

Conversation

@bashandbone

@bashandbone bashandbone commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

🚨 Severity: CRITICAL/HIGH
đź’ˇ Vulnerability: Path Traversal in TypeScript dependency extraction. When manually normalizing imported modules that escape the base directory (e.g. ../../../), the logic popped ParentDir unrestrictedly or discarded it, which could trick the resolution system into incorrectly interpreting file locations and subverting later bounds checks.
🎯 Impact: A maliciously crafted project or dependency tree could force the extraction engine to resolve logic, cache invalidation hashes, or access structures pointing to arbitrary files on the execution system inside the thread processing boundaries if standard canonicalization bypassed them.
đź”§ Fix: Updated Component::ParentDir behavior inside resolved.components() to check if the path is empty or already ends in ParentDir. In those cases, it safely pushes ParentDir. It also blocks popping RootDir and Prefix.
âś… Verification: Run cargo test -p thread-flow --test extractor_typescript_tests and ensure the code changes cause no side-effects and that relative components are correctly persisted out-of-bounds.


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

Summary by Sourcery

Harden TypeScript dependency path resolution against parent-directory traversal and make minor code cleanups across AST and rule engine modules.

Bug Fixes:

  • Prevent unsafe normalization of parent-directory components when resolving TypeScript dependency paths to avoid traversing beyond allowed roots.

Enhancements:

  • Simplify lifetimes in rule-engine variable checking helpers by taking borrowed references directly.
  • Apply minor formatting and readability improvements in AST engine string handling, Tree-sitter parser tests, and rule registration accessors.

Documentation:

  • Add a Sentinel incident note documenting the TypeScript extractor path traversal vulnerability, its root cause, and preventative guidelines.

Chores:

  • Record the security remediation details under the internal .jules Sentinel documentation directory.

In `crates/flow/src/incremental/extractors/typescript.rs`, manual path
normalization failed to correctly handle out-of-bounds `../`
(ParentDir) references. When resolving paths outside the base tree,
it would mistakenly pop `ParentDir` blindly or ignore it if the
component list was empty.

This update explicitly handles `std::path::Component::ParentDir`. If
the component list is empty or the last component is `ParentDir`, we
safely push it to preserve the traversal instead of swallowing it.
Additionally, it blocks popping `RootDir` or `Prefix` elements to
prevent arbitrary escapes.

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.

@sourcery-ai

sourcery-ai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Fixes a critical path traversal bug in the TypeScript dependency extractor’s manual path normalization by correctly handling ParentDir components and root boundaries, plus some minor refactors/formatting changes in AST and rule-engine code and adds a Sentinel incident note.

Flow diagram for updated ParentDir handling in TypeScript dependency extraction

flowchart TD
    A[Component is ParentDir] --> B{components is empty?}
    B -- Yes --> C[Push ParentDir onto components]
    B -- No --> D[Get last component]
    D --> E{last is ParentDir?}
    E -- Yes --> F[Push ParentDir onto components]
    E -- No --> G{last is RootDir or Prefix?}
    G -- Yes --> H[Do nothing]
    G -- No --> I[Pop last component from components]
Loading

File-Level Changes

Change Details Files
Harden ParentDir handling in TypeScript dependency extraction to prevent path traversal outside the allowed root.
  • Replace unconditional pop on ParentDir components with logic that pushes ParentDir when the stack is empty or already ends with ParentDir.
  • Prevent popping RootDir or Prefix components when processing ParentDir, preserving correct root semantics.
  • Maintain behavior of ignoring CurDir and pushing all other components as-is.
crates/flow/src/incremental/extractors/typescript.rs
Minor cleanup and formatting improvements in AST engine and rule engine code.
  • Inline unwrap_or_else formatting for String::from_utf8 error recovery in ContentExt implementation.
  • Reformat long assertions and iterator/map chains for readability.
  • Simplify Registration::read by reducing line breaks in unwrap_or_else chain.
  • Remove unnecessary lifetime parameters from internal helper functions by changing references to use elided lifetimes.
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 Sentinel incident and remediation for the TypeScript dependency path traversal issue.
  • Add a Sentinel markdown entry describing the vulnerability, root cause, learnings, and prevention guidelines for manual path normalization.
.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 ParentDir handling in the TypeScript extractor, the branch where the last component is RootDir or Prefix currently drops the ParentDir entirely; this seems to conflict with the sentinel note about preserving out-of-bounds .. components—consider either explicitly documenting this choice or pushing a ParentDir in those cases if you truly want to track traversal above the base.
  • The new ParentDir normalization logic is fairly intricate; consider extracting it into a small helper (e.g., fn push_parent_dir(components: &mut Vec<Component>)) so its edge-case behavior (empty stack, stacked ParentDir, RootDir/Prefix) is easier to read and reason about.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In the `ParentDir` handling in the TypeScript extractor, the branch where the last component is `RootDir` or `Prefix` currently drops the `ParentDir` entirely; this seems to conflict with the sentinel note about preserving out-of-bounds `..` components—consider either explicitly documenting this choice or pushing a `ParentDir` in those cases if you truly want to track traversal above the base.
- The new `ParentDir` normalization logic is fairly intricate; consider extracting it into a small helper (e.g., `fn push_parent_dir(components: &mut Vec<Component>)`) so its edge-case behavior (empty stack, stacked `ParentDir`, `RootDir`/`Prefix`) is easier to read and reason about.

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.

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.

1 participant