Skip to content

🛡️ Sentinel: [CRITICAL] Fix path traversal in TypeScript module resolution#266

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

🛡️ Sentinel: [CRITICAL] Fix path traversal in TypeScript module resolution#266
bashandbone wants to merge 1 commit into
mainfrom
sentinel-fix-path-traversal-typescript-extractor-15949326259489310145

Conversation

@bashandbone
Copy link
Copy Markdown
Contributor

@bashandbone bashandbone commented May 26, 2026

🚨 Severity: CRITICAL
💡 Vulnerability: A path traversal vulnerability existed in crates/flow/src/incremental/extractors/typescript.rs within the resolve_module manual path normalization fallback. When std::fs::canonicalize fails (e.g., if the file doesn't exist yet), the code manually resolves .. components by blindly popping from a stack of components. This permitted escaping absolute bounds (popping RootDir) and corrupted relative parent traversals (e.g., dropping ../ components entirely rather than preserving them).
🎯 Impact: An attacker or malformed module specifier could traverse outside the intended extraction boundaries, resolving or referencing files inappropriately.
🔧 Fix: Updated the Component::ParentDir match arm to safely inspect the last item on the component stack. It explicitly prevents popping RootDir and Prefix components, and it preserves .. components when climbing out of a relative directory by pushing ParentDir onto the stack if it's empty or already ends in ParentDir. Added an inline comment documenting the path traversal block.
Verification:

  1. Ran cargo test -p thread-flow --test extractor_typescript_tests which verifies module resolutions are correct.
  2. Code review has analyzed the fix as functional and safe against root popping.
  3. Added a learning entry to .jules/sentinel.md detailing the vulnerability pattern to prevent similar occurrences.

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

Summary by Sourcery

Fix unsafe manual path normalization in TypeScript module resolution and document the vulnerability pattern for future prevention.

Bug Fixes:

  • Harden manual handling of parent directory components in TypeScript module resolution to prevent path traversal outside intended boundaries.

Documentation:

  • Add a Sentinel learning entry documenting the manual path normalization vulnerability and its prevention guidelines.

…ution

Fixes a critical path traversal vulnerability in `crates/flow/src/incremental/extractors/typescript.rs` where manual path normalization blindly popped directory components when resolving `..`. This allowed traversal paths like `/..` to strip the root directory (`/`), or escaping above the starting boundary when traversing upwards via `../../`.

The fix correctly checks the last component in the stack, preventing the popping of `RootDir` and `Prefix`, and correctly pushing `ParentDir` when the stack is empty or already at `ParentDir`.

Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 26, 2026 17:55
@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 26, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Fixes a critical path traversal vulnerability in the TypeScript module resolver’s manual path normalization fallback by making ParentDir handling root/prefix-safe and documenting the vulnerability pattern in Sentinel notes.

File-Level Changes

Change Details Files
Harden manual path normalization in TypeScript module resolution to prevent unsafe parent directory traversal beyond roots and to correctly preserve relative .. components.
  • Update the Component::ParentDir match arm to inspect the last stacked component before mutating it.
  • Disallow popping RootDir and Prefix components when processing ParentDir, effectively blocking traversal above the filesystem root or drive prefix.
  • When the stack is empty or ends in ParentDir, push an additional ParentDir instead of popping, preserving correct relative upward traversal semantics.
  • Maintain existing behavior for current directory and other path components while ensuring the component stack is mutated safely.
  • Add an inline comment clarifying that root and prefix popping is intentionally blocked as a path traversal protection.
crates/flow/src/incremental/extractors/typescript.rs
Record the vulnerability pattern and remediation guidance in the project’s Sentinel learning documentation.
  • Add a Sentinel entry describing the original path traversal vulnerability in manual path normalization.
  • Document the correct handling of Component::ParentDir to avoid popping root/prefix components and to preserve leading .. segments when traversing above the starting directory.
.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 nested if let + match inside the ParentDir arm is getting a bit dense; consider extracting this logic into a small helper function (e.g., fn handle_parent_dir(components: &mut Vec<Component>)) to make the control flow and invariants clearer and easier to validate.
  • In the ParentDir handling, the behavior for Windows-specific Component::Prefix and related path forms is subtle; it may be worth explicitly documenting (in code comments) the intended semantics for UNC/prefixed paths so future changes don’t inadvertently reintroduce traversal issues on non-Unix platforms.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The nested `if let` + `match` inside the `ParentDir` arm is getting a bit dense; consider extracting this logic into a small helper function (e.g., `fn handle_parent_dir(components: &mut Vec<Component>)`) to make the control flow and invariants clearer and easier to validate.
- In the `ParentDir` handling, the behavior for Windows-specific `Component::Prefix` and related path forms is subtle; it may be worth explicitly documenting (in code comments) the intended semantics for UNC/prefixed paths so future changes don’t inadvertently reintroduce traversal issues on non-Unix platforms.

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

This PR hardens the TypeScript dependency extractor’s manual path normalization fallback to prevent path traversal issues when canonicalize() fails, and adds a Sentinel learning entry documenting the vulnerability pattern.

Changes:

  • Updated Component::ParentDir handling in resolve_module_path to avoid popping RootDir/Prefix and to preserve leading .. for relative paths.
  • Added a .jules/sentinel.md entry documenting the manual path normalization pitfall and prevention guidance.

Reviewed changes

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

File Description
crates/flow/src/incremental/extractors/typescript.rs Hardens manual .. normalization to prevent root/prefix popping and preserve relative parent traversals.
.jules/sentinel.md Documents the vulnerability pattern and recommended prevention approach.

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

Comment thread .jules/sentinel.md
Comment on lines +1 to +2
## 2024-05-24 - [Path Traversal Vulnerability in Manual Path Resolution]
**Vulnerability:** Path traversal vulnerability during manual path normalization.
Comment on lines 810 to +825
std::path::Component::ParentDir => {
components.pop();
if let Some(last) = components.last() {
match last {
std::path::Component::RootDir | std::path::Component::Prefix(_) => {
// Path traversal block: do not pop root or prefix
}
std::path::Component::ParentDir => {
components.push(component);
}
_ => {
components.pop();
}
}
} else {
components.push(component);
}
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