Skip to content

🛡️ Sentinel: [HIGH] Fix Path Traversal in TypeScript Module Resolution#157

Open
bashandbone wants to merge 1 commit intomainfrom
sentinel-fix-path-traversal-817992255317682365
Open

🛡️ Sentinel: [HIGH] Fix Path Traversal in TypeScript Module Resolution#157
bashandbone wants to merge 1 commit intomainfrom
sentinel-fix-path-traversal-817992255317682365

Conversation

@bashandbone
Copy link
Copy Markdown
Contributor

@bashandbone bashandbone commented Apr 17, 2026

🚨 Severity: HIGH
💡 Vulnerability: The resolve_module_path in crates/flow/src/incremental/extractors/typescript.rs used a blind components.pop() to handle .. (ParentDir) components in manual path normalization. This was flawed because if the path started with .., or if .. was evaluated against the root directory (/) or a drive prefix (C:\), it would improperly discard these important root or prefix components, potentially changing absolute paths to relative ones, escaping directories, or causing resolution mismatches.
🎯 Impact: Attackers could potentially exploit this manual path normalization behavior when parsing adversarial imports or files, allowing resolution outside of the intended extraction boundary, which is a classic path traversal risk.
🔧 Fix: Replaced the blind .pop() with a match statement on components.last(). It explicitly checks for RootDir and Prefix to prevent escaping above the root. It correctly pops Normal components, and it safely retains ParentDir (pushes it back onto the stack) when resolving at the root level of a relative path (e.g. ../../a).
✅ Verification: Ran cargo test -p thread-flow --test extractor_typescript_tests which confirmed 25 module resolution tests passed with no regressions.


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

Summary by Sourcery

Fix path traversal handling in TypeScript module resolution by hardening manual path normalization and document the vulnerability and prevention guidance in Sentinel notes.

Bug Fixes:

  • Correct parent directory component handling during manual path normalization to prevent escaping above filesystem roots or prefixes in TypeScript module resolution.

Documentation:

  • Add Sentinel security note documenting the path traversal vulnerability, its root cause, and best practices for safe path normalization.

…ution

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 April 17, 2026 17:54
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Apr 17, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Fixes a path traversal vulnerability in TypeScript module resolution by making manual path normalization robust against .. components that attempt to traverse above root or discard drive prefixes, and documents the issue in the Sentinel security log.

Class diagram for TypeScriptDependencyExtractor path resolution changes

classDiagram
    class TypeScriptDependencyExtractor {
        +resolve_module_path(resolved_path) PathBuf
    }

    class PathNormalization {
        +components Vec_Component
        +normalize(resolved_path) PathBuf
        +handle_parent_dir(components, component) void
        +handle_cur_dir(components, component) void
        +handle_other(components, component) void
    }

    class Component {
        <<enum>>
        RootDir
        Prefix
        Normal
        CurDir
        ParentDir
    }

    TypeScriptDependencyExtractor --> PathNormalization : uses
    PathNormalization --> Component : iterates_over

    class Vec_Component {
        +push(component) void
        +pop() Option_Component
        +last() Option_Component
    }
Loading

File-Level Changes

Change Details Files
Harden manual path normalization logic when processing ParentDir components during TypeScript module resolution to prevent traversing above root or corrupting relative paths.
  • Replace blind components.pop() on ParentDir with a match on components.last() to differentiate between RootDir, Prefix, Normal, and other cases.
  • Block ParentDir from removing RootDir or Prefix components, preventing escape above filesystem roots or drive prefixes.
  • Allow ParentDir to pop prior Normal components, preserving standard .. handling within a directory tree.
  • Preserve leading ParentDir components (e.g., ../../a) by pushing them when the stack is empty or the last component is also ParentDir.
crates/flow/src/incremental/extractors/typescript.rs
Add Sentinel security documentation capturing the vulnerability, its root cause, and prevention guidance.
  • Create .jules/sentinel.md with an entry describing the manual path normalization issue and the correct handling of ParentDir with respect to RootDir and Prefix.
  • Document the learning and prevention notes to guide future changes involving manual path resolution.
.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 left some high level feedback:

  • The ParentDir handling logic would be clearer and less error-prone if the _ arm were split into explicit cases (e.g., None vs Some(ParentDir)), so future readers don’t have to infer the intended behavior for empty stacks versus nested .. segments.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `ParentDir` handling logic would be clearer and less error-prone if the `_` arm were split into explicit cases (e.g., `None` vs `Some(ParentDir)`), so future readers don’t have to infer the intended behavior for empty stacks versus nested `..` segments.

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.

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

Addresses a high-severity path traversal risk in TypeScript module resolution by fixing incorrect manual path normalization when handling .. (Component::ParentDir) components.

Changes:

  • Updates resolve_module_path manual normalization to prevent popping RootDir / Prefix components when processing ParentDir.
  • Preserves leading .. segments for relative paths (e.g., ../../a) instead of incorrectly discarding them.
  • Adds a Sentinel write-up documenting the vulnerability and prevention guidance.

Reviewed changes

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

File Description
crates/flow/src/incremental/extractors/typescript.rs Fixes manual normalization logic for .. to avoid root/prefix loss and incorrect path rewriting.
.jules/sentinel.md Documents the incident/learning around safe manual normalization with std::path::Component.

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

Comment on lines +810 to +821
std::path::Component::ParentDir => match components.last() {
Some(std::path::Component::RootDir)
| Some(std::path::Component::Prefix(_)) => {
// Cannot go above root
}
Some(std::path::Component::Normal(_)) => {
components.pop();
}
_ => {
components.push(component);
}
},
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

The new ParentDir normalization logic is security-sensitive but currently isn’t covered by an automated regression test. Please add a test case that forces the manual normalization path (canonicalize fails) with an absolute source_file and an import containing enough .. segments to hit the root, then assert the result remains absolute (i.e., root/prefix is preserved and not dropped). This would prevent future regressions back to the prior components.pop() behavior.

Copilot uses AI. Check for mistakes.
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