Skip to content

🛡️ Sentinel: [CRITICAL] Fix path traversal in manual path normalization#217

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

🛡️ Sentinel: [CRITICAL] Fix path traversal in manual path normalization#217
bashandbone wants to merge 1 commit intomainfrom
sentinel/fix-path-traversal-1072408770329239754

Conversation

@bashandbone
Copy link
Copy Markdown
Contributor

@bashandbone bashandbone commented May 9, 2026

🚨 Severity: CRITICAL
đź’ˇ Vulnerability: Path traversal vulnerability in TypeScriptDependencyExtractor. When canonicalize() fails, manual path normalization blindly popped components when encountering .. (ParentDir), potentially popping RootDir or Prefix and escaping boundary restrictions, or ignoring .. entirely at the root of a relative path.
🎯 Impact: An attacker could potentially extract dependencies or access files outside of the intended directory context via maliciously crafted import paths containing excessive .. components.
đź”§ Fix: Updated the manual std::path::Component loop to securely handle ParentDir by: (1) pushing it if the current component list is empty or already ends in ParentDir, and (2) not popping if the current end is RootDir or Prefix.
âś… Verification: Ran cargo check -p thread-flow and verified functionality via cargo test -p thread-flow --test extractor_typescript_tests. Both compile and pass perfectly.


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

Summary by Sourcery

Harden TypeScript dependency extraction path normalization to prevent directory traversal and document the incident and remediation in Sentinel notes.

Bug Fixes:

  • Prevent manual path normalization from allowing .. components to escape root or prefix boundaries in the TypeScript dependency extractor.

Documentation:

  • Add a Sentinel incident entry describing the path traversal vulnerability, its cause, and prevention guidelines.

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

sourcery-ai Bot commented May 9, 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 by hardening handling of ParentDir components, and documents the issue and mitigation in a Sentinel security note.

Flow diagram for secure ParentDir handling in manual path normalization

flowchart TD
    Start[ParentDir component encountered] --> CheckEmpty[Is components list empty?]
    CheckEmpty -->|Yes| PushParentEmpty[Push ParentDir onto components]
    PushParentEmpty --> End[Continue to next component]
    CheckEmpty -->|No| CheckLastParent[Does last component equal ParentDir?]
    CheckLastParent -->|Yes| PushParentChain[Push ParentDir onto components]
    PushParentChain --> End
    CheckLastParent -->|No| CheckBoundary[Is last component RootDir or Prefix?]
    CheckBoundary -->|Yes| KeepBoundary[Do not pop; keep boundary]
    KeepBoundary --> End
    CheckBoundary -->|No| PopComponent[Pop last component from components]
    PopComponent --> End
Loading

File-Level Changes

Change Details Files
Harden manual path normalization to prevent ParentDir components from escaping root/prefix boundaries during TypeScript dependency extraction.
  • Update the ParentDir match arm in the component-folding loop to compute whether the accumulated components list is empty, ends with another ParentDir, or ends with RootDir/Prefix.
  • Change the behavior so that ParentDir is pushed when the component stack is empty or already ends with ParentDir, and only pops a component when the stack is non-empty and does not end with RootDir or Prefix.
  • Leave handling of CurDir as a no-op and keep pushing all other components unchanged.
crates/flow/src/incremental/extractors/typescript.rs
Add a Sentinel security note describing the vulnerability, lessons learned, and prevention guidance.
  • Create a new Sentinel markdown file documenting the path traversal vulnerability in the TypeScript dependency extractor.
  • Summarize the root cause (unsafe manual normalization), the key learning about respecting RootDir/Prefix boundaries, and recommended prevention strategies for 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 ParentDir handling block repeatedly calls components.last() and re-pattern-matches it; consider binding let last = components.last(); once and deriving is_parent / is_root from that to simplify the logic and reduce the chance of subtle discrepancies.
  • If the intent is to preserve leading .. segments only for relative paths, it might be clearer to explicitly distinguish absolute vs. relative paths (or current boundary state) in this normalization function, rather than relying solely on the is_empty/is_parent checks when deciding whether to push or pop ParentDir.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `ParentDir` handling block repeatedly calls `components.last()` and re-pattern-matches it; consider binding `let last = components.last();` once and deriving `is_parent` / `is_root` from that to simplify the logic and reduce the chance of subtle discrepancies.
- If the intent is to preserve leading `..` segments only for relative paths, it might be clearer to explicitly distinguish absolute vs. relative paths (or current boundary state) in this normalization function, rather than relying solely on the `is_empty`/`is_parent` checks when deciding whether to push or pop `ParentDir`.

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 addresses a path traversal vulnerability in the TypeScript dependency extractor’s manual path normalization fallback (used when canonicalize() fails), ensuring .. handling can’t pop past RootDir/Prefix or silently erase traversal at the start of relative paths.

Changes:

  • Hardened manual std::path::Component normalization to treat ParentDir safely around root/prefix boundaries.
  • Added a Sentinel note 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 Updates manual path component reduction logic to prevent boundary-escaping behavior when resolving ...
.jules/sentinel.md Adds a security “sentinel” write-up capturing the issue and mitigation guidance.
Comments suppressed due to low confidence (1)

crates/flow/src/incremental/extractors/typescript.rs:831

  • The new manual ParentDir handling is a security-critical normalization change but there’s no regression test covering the previously-vulnerable cases (e.g., canonicalize() failing + excessive .. that would previously pop past RootDir/Prefix or incorrectly erase leading .. on relative paths). Please add a test that exercises resolve_module_path with such module specifiers and asserts the normalized path preserves boundaries (RootDir/Prefix) and/or retains leading .. when appropriate.
            // Normalize the path to resolve ../ components
            if let Ok(canonical) = resolved.canonicalize() {
                resolved = canonical;
            } else {
                // If canonicalize fails (file doesn't exist), manually resolve
                let mut components = Vec::new();
                for component in resolved.components() {
                    match component {
                        std::path::Component::ParentDir => {
                            let is_empty = components.is_empty();
                            let is_parent = matches!(
                                components.last(),
                                Some(std::path::Component::ParentDir)
                            );
                            let is_root = matches!(
                                components.last(),
                                Some(std::path::Component::RootDir | std::path::Component::Prefix(_))
                            );
                            if is_empty || is_parent {
                                components.push(component);
                            } else if !is_root {
                                components.pop();
                            }
                        }
                        std::path::Component::CurDir => {}
                        _ => components.push(component),
                    }
                }
                resolved = components.iter().collect();
            }

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

Comment thread .jules/sentinel.md
Comment on lines +1 to +4
## 2026-05-09 - Prevent Path Traversal in Manual Path Resolution
**Vulnerability:** The TypeScript dependency extractor (`crates/flow/src/incremental/extractors/typescript.rs`) manually normalized paths without preventing `ParentDir` components from popping `RootDir` or `Prefix`, allowing paths to escape the intended directory.
**Learning:** Manual path normalization (e.g., when `canonicalize()` fails) must strictly handle standard library boundaries like `RootDir` and `Prefix` to prevent path traversal outside of absolute or project boundaries.
**Prevention:** Always check if the path component being popped represents a boundary, or use robust external path normalization libraries instead of rolling custom loops with `std::path::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