Skip to content

🛡️ Sentinel: [HIGH] Fix path traversal in manual path normalization#271

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

🛡️ Sentinel: [HIGH] Fix path traversal in manual path normalization#271
bashandbone wants to merge 1 commit into
mainfrom
sentinel-path-traversal-fix-10888592995321208738

Conversation

@bashandbone
Copy link
Copy Markdown
Contributor

@bashandbone bashandbone commented May 28, 2026

🚨 Severity: HIGH
💡 Vulnerability: The manual path normalization for unresolved paths in crates/flow/src/incremental/extractors/typescript.rs incorrectly popped std::path::Component::ParentDir from the components list regardless of the previous component. This could pop RootDir or Prefix components, leading to path traversal vulnerabilities and incorrect path resolution for multiple .. segments.
🎯 Impact: An attacker could potentially use maliciously crafted import paths with multiple .. segments to traverse out of the intended directory and access sensitive files, especially when manual canonicalization is triggered for non-existent or unresolvable paths.
🔧 Fix: Updated the Component::ParentDir match arm to safely handle popping components. It now ignores ParentDir if the last component is RootDir or Prefix, pushes ParentDir if the components list is empty or the last component is also a ParentDir, and otherwise safely pops the last directory.
✅ Verification: Ran cargo test -p thread-flow --test extractor_typescript_tests to verify no functionality is broken and path resolutions succeed correctly.


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

Summary by Sourcery

Harden manual path normalization in the TypeScript dependency extractor to prevent unsafe handling of parent directory components in module path resolution.

Bug Fixes:

  • Prevent path traversal and incorrect absolute path resolution by safely handling ParentDir components when normalizing unresolved module paths.

Documentation:

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

- Updated `resolve_module_path` manual path normalization to safely handle `Component::ParentDir`.
- Prevents popping `RootDir` or `Prefix` components during manual canonicalization of non-existent paths.

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

sourcery-ai Bot commented May 28, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Fixes manual path normalization in the TypeScript dependency extractor to safely handle .. components and adds a Sentinel write-up documenting the path traversal vulnerability and its remediation.

File-Level Changes

Change Details Files
Harden manual path normalization logic for unresolved module paths to prevent unsafe handling of .. components.
  • Update the Component::ParentDir match arm to inspect the last collected component before modifying the path stack.
  • Prevent popping RootDir or Prefix components when encountering ParentDir, effectively ignoring traversal above the filesystem root or drive prefix.
  • Push ParentDir when the components list is empty or the last component is also ParentDir, preserving unresolved upward traversal in relative contexts.
  • Pop the last non-root, non-prefix component for ParentDir to perform safe directory backtracking during normalization.
crates/flow/src/incremental/extractors/typescript.rs
Document the discovered path traversal vulnerability and remediation details for future reference.
  • Add a Sentinel incident entry describing the original bug in resolve_module_path and its impact on path traversal and absolute path correctness.
  • Capture the key learning that std::path::Component allows popping structural elements such as RootDir and must be handled explicitly when normalizing paths.
  • Record prevention guidelines for safely handling ParentDir by checking the last component and treating root/prefix and chained ParentDir cases carefully.
.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

Fixes a path-traversal-style bug in TypeScriptDependencyExtractor::resolve_module_path's manual fallback normalization (used when canonicalize() fails for relative imports). Previously, .. components were blindly popped, which could remove RootDir/Prefix components and produce incorrect paths or escape intended directories. The match arm now checks the previous component before popping. A .jules/sentinel.md note documents the lesson.

Changes:

  • Replace unconditional components.pop() for ParentDir with a guarded handler that preserves RootDir/Prefix, accumulates ParentDir when at start or after another ParentDir, and otherwise pops the last component.
  • Add .jules/sentinel.md documenting the vulnerability, 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 Safer ParentDir normalization in manual fallback for unresolved relative imports.
.jules/sentinel.md New lesson-log entry describing the bug and prevention.

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

Comment thread .jules/sentinel.md
@@ -0,0 +1,4 @@
## 2024-05-18 - [Path Traversal in Manual Path Resolution]
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