Skip to content

🛡️ Sentinel: [CRITICAL] Fix path traversal in dependency extractor#260

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

🛡️ Sentinel: [CRITICAL] Fix path traversal in dependency extractor#260
bashandbone wants to merge 1 commit into
mainfrom
sentinel/fix-path-traversal-13040705844836331622

Conversation

@bashandbone
Copy link
Copy Markdown
Contributor

@bashandbone bashandbone commented May 24, 2026

🚨 Severity: CRITICAL
💡 Vulnerability: The fallback path normalization logic in the TypeScript dependency extractor (crates/flow/src/incremental/extractors/typescript.rs) incorrectly handled Component::ParentDir (..). It blindly popped the last component from the path. This allowed .. to pop the root directory (/), effectively allowing an attacker to pass an absolute path like /../../etc/passwd that would strip the root and become a relative traversal path, potentially bypassing directory bound checks. It also failed to correctly preserve multiple consecutive leading .. segments for valid relative paths.
🎯 Impact: Sandbox escape and arbitrary file access risk during static analysis if the analyzer processes malformed or malicious relative imports that attempt to traverse out of the base directory.
🔧 Fix: Updated the manual path resolution loop to properly match components.last(). It explicitly prevents ParentDir from popping RootDir or Prefix. If the list is empty or already ends with a ParentDir, the new ParentDir is pushed, properly maintaining valid relative paths (../../foo) while preventing escapes.
✅ Verification: Ensure tests pass locally by running cargo test -p thread-flow. Verified building without clippy warnings using cargo clippy -p thread-flow -- -D warnings.


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

Summary by Sourcery

Fix unsafe manual path normalization in the TypeScript dependency extractor to prevent path traversal escapes and document the incident in Sentinel notes.

Bug Fixes:

  • Harden handling of parent directory components in the TypeScript dependency extractor's fallback path normalization to prevent escaping the root or prefix while preserving valid relative paths.

Documentation:

  • Add a Sentinel security incident note documenting the path traversal vulnerability, its root cause, and prevention guidance for manual path canonicalization.

This commit fixes a path traversal vulnerability in `crates/flow/src/incremental/extractors/typescript.rs`. The manual path normalization fallback incorrectly popped `RootDir` and `Prefix` components when encountering `..` (`ParentDir`). The fix prevents popping root components and correctly preserves leading `..` for valid relative paths.

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

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Fixes a critical path traversal vulnerability in the TypeScript dependency extractor’s manual path normalization, and documents the issue and remediation guidance in a Sentinel security note.

File-Level Changes

Change Details Files
Harden manual path normalization to correctly handle ParentDir components without allowing root/prefix escape and while preserving valid relative traversal segments.
  • Replace unconditional pop on encountering Component::ParentDir with logic that inspects the last accumulated component.
  • Prevent ParentDir from removing RootDir or Prefix components, effectively blocking absolute-path-based traversal out of the sandbox root.
  • Ensure that when the accumulated list is empty or already ends with ParentDir, additional ParentDir components are preserved instead of collapsed, maintaining correct relative paths like ../../foo.
  • Leave handling for CurDir and other components unchanged, continuing to skip CurDir and push all other path components.
crates/flow/src/incremental/extractors/typescript.rs
Add Sentinel security documentation capturing the path traversal vulnerability, its root cause, and prevention guidance for future path normalization implementations.
  • Create a new Sentinel markdown entry describing the original vulnerability in the TypeScript module resolver fallback normalization.
  • Document the learning about incorrect ParentDir handling when canonicalize fails and how it enabled sandbox escape/arbitrary file read risk.
  • Record preventive guidelines for safely implementing manual canonicalization with std::path::Components, including explicit handling rules for RootDir, Prefix, and ParentDir 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 reviewed your changes and they look great!


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 fallback path normalization to prevent .. components from escaping an absolute path’s RootDir/Prefix, addressing a path traversal risk when canonicalize() fails. It also adds Sentinel documentation capturing the incident and guidance for safe manual canonicalization.

Changes:

  • Update manual components()-based normalization to avoid popping RootDir/Prefix and to preserve leading/consecutive .. for relative paths.
  • Add a Sentinel incident note documenting the vulnerability, root cause, and prevention guidance.

Reviewed changes

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

File Description
crates/flow/src/incremental/extractors/typescript.rs Hardens .. handling in the canonicalize() fallback normalization logic.
.jules/sentinel.md Adds security incident documentation for the path traversal issue and prevention guidance.

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

Comment on lines +811 to +816
// SECURITY: Prevent path traversal from escaping root or prefix
match components.last() {
Some(std::path::Component::Prefix(_)) | Some(std::path::Component::RootDir) => {}
Some(std::path::Component::ParentDir) | None => { components.push(component); }
_ => { components.pop(); }
}
Comment thread .jules/sentinel.md
Comment on lines +1 to +4
## 2024-05-24 - Path Traversal in Dependency Extractor
**Vulnerability:** A path traversal vulnerability (sandbox escape/arbitrary file read risk) existed in the TypeScript module resolver's fallback path normalization logic (`crates/flow/src/incremental/extractors/typescript.rs`).
**Learning:** When `std::path::PathBuf::canonicalize` fails (e.g., file not found during static analysis), the manual fallback normalization blindly called `components.pop()` when encountering `Component::ParentDir` (`..`). This allowed an attacker or malformed file to pass `../../etc/passwd`, causing `..` to pop the root directory (`/`), effectively turning an absolute path into a relative one that bypassed the configured base directory bounds when subsequently joined. Furthermore, it improperly handled consecutive leading `..` components by ignoring them.
**Prevention:** When manually implementing path canonicalization using `std::path::Components`, always match against the current `components.last()`. Explicitly prevent `Component::ParentDir` from popping `Component::RootDir` or `Component::Prefix(_)`. If the list is empty or the last component is already `Component::ParentDir`, the new `ParentDir` must be pushed instead of popped to correctly maintain valid relative paths.
Comment thread .jules/sentinel.md
@@ -0,0 +1,4 @@
## 2024-05-24 - Path Traversal in Dependency Extractor
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