Skip to content

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

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

🛡️ Sentinel: [CRITICAL] Fix path traversal risk in TypeScript module resolution#237
bashandbone wants to merge 1 commit into
mainfrom
sentinel-fix-path-traversal-2592889757875481194

Conversation

@bashandbone
Copy link
Copy Markdown
Contributor

@bashandbone bashandbone commented May 16, 2026

🚨 Severity: CRITICAL
đź’ˇ Vulnerability: The path resolution logic for TypeScript imports (crates/flow/src/incremental/extractors/typescript.rs) used std::path::Component sequentially. When hitting a ParentDir (..), it unconditionally removed the last element from the path stack. This allowed malicious payloads with ../../ structures to bypass RootDir limitations or incorrectly flatten valid complex paths, leading to path traversal outside expected boundaries.
🎯 Impact: Exploitation of this flaw could allow attackers parsing malicious or crafted TypeScript code bases to cause the module graph resolver to inspect arbitrary files on the local filesystem outside of the provided module tree (depending on sandbox strictness), acting as a blind path-traversal primitive during module extraction.
đź”§ Fix: We updated the resolution logic to check the last() component on the stack. Now, ParentDir will only pop() if the top of the stack is a Normal component. If it's a RootDir or Prefix, the ParentDir is safely ignored (cannot traverse above root). If the stack is empty or ends with another ParentDir, the ParentDir is pushed, correctly preserving paths like ../../a.
âś… Verification: We ran the thread-flow unit tests (specifically extractor_typescript_tests) and verified cargo clippy -p thread-flow passes correctly. I also performed manual tests with isolated payloads to verify the root escape path behavior.


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

Summary by Sourcery

Harden TypeScript dependency extractor path normalization to prevent path traversal above the configured root and document the incident and lessons learned.

Bug Fixes:

  • Guard manual path normalization against escaping root or prefix when handling ParentDir components in the TypeScript dependency extractor.

Documentation:

  • Add Sentinel incident note describing the path traversal vulnerability, its root cause, and prevention guidelines for future path normalization logic.

…resolution

This commit fixes a vulnerability in `crates/flow/src/incremental/extractors/typescript.rs` where manual path component resolution could unconditionally pop the `RootDir` or improperly handle multiple consecutive `ParentDir`s (`..`).

By properly verifying the previous path component type, `..` correctly handles boundaries, preventing potential sandboxing escapes and module graph corruption.

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 May 16, 2026 17:56
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 16, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts TypeScript module path normalization to prevent escaping the root via .. components, and documents the vulnerability and fix in a Sentinel incident note.

Flow diagram for updated ParentDir handling in TypeScript path normalization

flowchart TD
    A[Component is ParentDir] --> B{Last component on stack}
    B -->|Normal| C[Pop last component]
    B -->|RootDir or Prefix| D[Do nothing]
    B -->|None or ParentDir or other| E[Push ParentDir onto stack]
Loading

File-Level Changes

Change Details Files
Harden manual path normalization for TypeScript module resolution against path traversal via ...
  • Change handling of std::path::Component::ParentDir to inspect the last stacked component before mutating the component stack.
  • Only pop the stack when the last component is a Normal path segment, leaving RootDir and Prefix intact to prevent traversing above the root.
  • Preserve leading and consecutive ParentDir components by pushing them when the stack is empty or ends with a non-Normal component, so relative paths like ../../a are represented correctly.
  • Keep behavior for CurDir and other components unchanged, still pushing them directly onto the stack.
crates/flow/src/incremental/extractors/typescript.rs
Add Sentinel documentation describing the path traversal vulnerability and defensive guidance.
  • Create a Sentinel incident markdown file summarizing the original vulnerability in manual path normalization.
  • Document the key learning around not allowing ParentDir to pop RootDir or Prefix and the need to preserve consecutive ParentDirs.
  • Record preventative guidance for future manual path normalization implementations using std::path::Component.
.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 new ParentDir handling logic is embedded inline in the loop; consider extracting it into a small helper function (e.g. normalize_parent_dir_component(&mut components)) so any other manual path normalization can reuse the same hardened behavior and stay consistent.
  • It may be worth double-checking how this logic behaves with Windows-specific prefixes (e.g. UNC paths or drive letters) and documenting any assumptions in code comments if certain Component::Prefix variants are not expected to appear in resolved paths.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new ParentDir handling logic is embedded inline in the loop; consider extracting it into a small helper function (e.g. `normalize_parent_dir_component(&mut components)`) so any other manual path normalization can reuse the same hardened behavior and stay consistent.
- It may be worth double-checking how this logic behaves with Windows-specific prefixes (e.g. UNC paths or drive letters) and documenting any assumptions in code comments if certain `Component::Prefix` variants are not expected to appear in `resolved` paths.

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

Hardens the manual path-component normalization used when canonicalize() fails inside TypeScriptDependencyExtractor::resolve_module_path, so that a ParentDir (..) only pops a real directory name. Encountering .. above a RootDir/Prefix is now ignored, and .. against an empty stack or another ParentDir is preserved. A short retrospective note is also added under .jules/.

Changes:

  • Replace the unconditional components.pop() on ParentDir with a check on the previous component to prevent escaping above / and to preserve consecutive ../ segments in relative paths.
  • Add .jules/sentinel.md describing the issue, learning, 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 Guards ParentDir handling against popping RootDir/Prefix and preserves consecutive .. components.
.jules/sentinel.md Adds a security retrospective entry describing the traversal fix.

đź’ˇ Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +811 to +819
// Prevent path traversal escaping root, and handle consecutive ParentDirs
let last = components.last().copied();
match last {
Some(std::path::Component::Normal(_)) => {
components.pop();
}
Some(std::path::Component::RootDir) | Some(std::path::Component::Prefix(_)) => {}
_ => 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