Skip to content

πŸ›‘οΈ Sentinel: [CRITICAL] Fix Path Traversal in TypeScript Module Path Resolution#228

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

πŸ›‘οΈ Sentinel: [CRITICAL] Fix Path Traversal in TypeScript Module Path Resolution#228
bashandbone wants to merge 1 commit into
mainfrom
sentinel/fix-path-traversal-10558821495673776827

Conversation

@bashandbone
Copy link
Copy Markdown
Contributor

@bashandbone bashandbone commented May 13, 2026

🚨 Severity: CRITICAL
πŸ’‘ Vulnerability: The manual path normalization fallback when canonicalizing failing paths in TypeScriptDependencyExtractor::resolve_module_path was simply blindly popping from the components vector on std::path::Component::ParentDir. This could allow traversal of arbitrary root or prefix paths (Component::RootDir / Component::Prefix) resulting in unanchoring absolute paths to relative ones, or dropping relative anchors by failing to add ParentDir to the front of the list when empty.
🎯 Impact: Attackers or poorly formatted path extraction dependencies could trigger arbitrary file reads, module inclusions, or extraction outside the bounds of the base system directories using crafted paths like ../../../../etc/passwd escaping normal limits.
πŸ”§ Fix: Updated the component normalization loop to accurately check the last element before popping. If the element is a RootDir or Prefix, it explicitly ignores popping. If the vector is empty or already ends with a ParentDir, it correctly pushes the new ParentDir to preserve relative structure (../../).
βœ… Verification: Ran extractor test cargo test -p thread-flow --test extractor_typescript_tests locally verifying all 25 parser behavior tests passed.


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

Summary by Sourcery

Harden TypeScript module path resolution against path traversal when canonicalization fails and document the vulnerability and fix in Sentinel notes.

Bug Fixes:

  • Prevent path traversal by ensuring manual path normalization does not pop root or prefix components and correctly preserves leading parent directory segments in relative paths.

Documentation:

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

…Resolution

Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 13, 2026 18:03
@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
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 13, 2026

Reviewer's Guide

Fixes a critical path traversal vulnerability in TypeScript module path resolution by making the manual path normalization logic root-aware and preserving relative parent directory components, and documents the incident and fix in a Sentinel note.

File-Level Changes

Change Details Files
Harden manual path normalization in TypeScriptDependencyExtractor to prevent path traversal and incorrect dropping of root or relative anchors.
  • Explicitly types the components vector as Vecstd::path::Component to clarify intent and type expectations.
  • Updates the ParentDir handling to inspect the last component before popping, preventing removal of RootDir or Prefix components.
  • Ensures that when the components vector is empty or already ends with ParentDir, an incoming ParentDir is pushed to preserve relative paths such as ../../a.
  • Keeps CurDir components ignored and all other components pushed unchanged, preserving existing behavior where safe.
crates/flow/src/incremental/extractors/typescript.rs
Add Sentinel documentation describing the path traversal vulnerability, its root cause, and prevention guidelines.
  • Creates a new sentinel markdown entry documenting the critical vulnerability in TypeScriptDependencyExtractor path resolution.
  • Summarizes the learning about incorrect ParentDir normalization and dropping of root/prefix components.
  • Provides prevention guidance for future manual normalization using std::path::Components.
.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

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="crates/flow/src/incremental/extractors/typescript.rs" line_range="807" />
<code_context>
             } else {
                 // If canonicalize fails (file doesn't exist), manually resolve
-                let mut components = Vec::new();
+                let mut components: Vec<std::path::Component> = Vec::new();
                 for component in resolved.components() {
                     match component {
</code_context>
<issue_to_address>
**issue (bug_risk):** Specify the lifetime parameter for `std::path::Component` to avoid a compilation error.

`std::path::Component` is declared as `pub enum Component<'a>`, so using `Vec<std::path::Component>` without a lifetime won’t compile. Either specify the lifetime (e.g. `Vec<std::path::Component<'_>>`) or drop the explicit type and rely on inference:

```rust
let mut components: Vec<std::path::Component<'_>> = Vec::new();
// or
let mut components = Vec::new();
```
</issue_to_address>

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.

} else {
// If canonicalize fails (file doesn't exist), manually resolve
let mut components = Vec::new();
let mut components: Vec<std::path::Component> = Vec::new();
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.

issue (bug_risk): Specify the lifetime parameter for std::path::Component to avoid a compilation error.

std::path::Component is declared as pub enum Component<'a>, so using Vec<std::path::Component> without a lifetime won’t compile. Either specify the lifetime (e.g. Vec<std::path::Component<'_>>) or drop the explicit type and rely on inference:

let mut components: Vec<std::path::Component<'_>> = Vec::new();
// or
let mut components = Vec::new();

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 manual path-normalization fallback in TypeScriptDependencyExtractor::resolve_module_path (used when canonicalize fails). The previous implementation unconditionally popped the components stack on ParentDir, which could erase a RootDir/Prefix anchor (turning an absolute path into a relative one) or silently drop excess .. segments. The new implementation inspects the last component and either ignores the ParentDir (when at root/prefix), pushes it (when empty or already on a ParentDir), or pops only a normal segment.

Changes:

  • Replace blind components.pop() on ParentDir with an explicit last-component check that preserves RootDir/Prefix anchors and accumulates leading .. components.
  • Add a Sentinel security note documenting the vulnerability and prevention guidance.

Reviewed changes

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

File Description
crates/flow/src/incremental/extractors/typescript.rs Safer path component normalization for the canonicalize fallback.
.jules/sentinel.md New Sentinel log entry describing the vulnerability and fix.

πŸ’‘ Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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