Skip to content

šŸ›”ļø Sentinel: [HIGH] Fix path traversal in manual path normalization#196

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

šŸ›”ļø Sentinel: [HIGH] Fix path traversal in manual path normalization#196
bashandbone wants to merge 1 commit intomainfrom
sentinel/fix-path-traversal-157728989311240504

Conversation

@bashandbone
Copy link
Copy Markdown
Contributor

@bashandbone bashandbone commented May 5, 2026

🚨 Severity: HIGH
šŸ’” Vulnerability: The typescript extractor manual path normalization (used when canonicalize() fails) suffered from a path traversal flaw. When reducing ../ (ParentDir) segments by popping from a vector of path components, the pop() method returned silently if the vector was empty. Consequently, paths starting with ../ lost those parent directory components, incorrectly anchoring relative references locally or resulting in unintended, out-of-bounds filesystem access attempts outside the original root directory.
šŸŽÆ Impact: An attacker could craft a dependency graph with ../ imports causing arbitrary reads out-of-bounds.
šŸ”§ Fix: Adjusted the manual normalization loop to track and push ../ components when safe (e.g. at the start of a relative path), ignore them at filesystem roots, and safely pop otherwise.
āœ… Verification: Verified that ../ references behave correctly mathematically and pass all tests via cargo test -p thread-flow --test extractor_typescript_tests.


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

Summary by Sourcery

Fix unsafe manual path normalization in the TypeScript dependency extractor to correctly handle parent directory components and prevent path traversal.

Bug Fixes:

  • Ensure manual path normalization preserves leading parent directory segments when appropriate and does not traverse beyond filesystem roots in the TypeScript extractor.

Documentation:

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

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

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Fixes a high-severity path traversal issue in the TypeScript dependency extractor’s manual path normalization by making ParentDir handling aware of stack state and filesystem roots, and documents the incident in the Sentinel log.

File-Level Changes

Change Details Files
Harden manual path normalization to safely handle leading and nested .. components without collapsing or escaping the intended root.
  • Replace naive unconditional ParentDir stack pop with logic that inspects the last component before acting.
  • Ensure leading or consecutive ParentDir components are preserved by pushing them when the component stack is empty or ends in ParentDir.
  • Drop ParentDir components when at filesystem roots or prefixes instead of modifying the stack.
  • Only pop a prior component when it is a normal path segment, preventing silent underflow and path mis-anchoring.
crates/flow/src/incremental/extractors/typescript.rs
Add a Sentinel incident document describing the vulnerability, its root cause, and prevention guidelines.
  • Create a .jules/sentinel.md entry summarizing the path traversal vulnerability in TypeScript extractor manual normalization.
  • Capture learnings about safe manual path normalization with vector reductions and root constraints.
  • Document preventative guidelines for handling ParentDir segments correctly in future changes.
.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 fairly subtle; consider extracting it into a small helper function (e.g., push_parent_dir_component(...)) or adding a short inline comment to document the intended behaviors for root/prefix/relative cases to make future maintenance easier.
  • Right now ParentDir components that would escape a root/prefix are silently dropped; if this is security-critical, consider whether propagating an explicit error or signaling this condition would make misuse less likely than silently clamping the path.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `ParentDir` handling logic is fairly subtle; consider extracting it into a small helper function (e.g., `push_parent_dir_component(...)`) or adding a short inline comment to document the intended behaviors for root/prefix/relative cases to make future maintenance easier.
- Right now `ParentDir` components that would escape a root/prefix are silently dropped; if this is security-critical, consider whether propagating an explicit error or signaling this condition would make misuse less likely than silently clamping the path.

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 HIGH-severity path traversal issue in the TypeScript extractor’s fallback (non-canonicalize()) path normalization logic, and records the incident/learning in Jules Sentinel notes.

Changes:

  • Update manual .. normalization to avoid silently dropping leading ParentDir components.
  • Add .jules/sentinel.md entry documenting the vulnerability, learning, 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 Adjusts manual path component reduction logic for .. handling when canonicalize() fails.
.jules/sentinel.md Adds a Sentinel note describing the traversal vulnerability and prevention guidance.

šŸ’” Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +810 to +819
std::path::Component::ParentDir => match components.last() {
Some(std::path::Component::ParentDir) | None => {
components.push(component)
}
Some(std::path::Component::RootDir)
| Some(std::path::Component::Prefix(_)) => {}
_ => {
components.pop();
}
},
Comment on lines 807 to +811
let mut components = Vec::new();
for component in resolved.components() {
match component {
std::path::Component::ParentDir => {
components.pop();
}
std::path::Component::ParentDir => match components.last() {
Some(std::path::Component::ParentDir) | None => {
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