Skip to content

🛡️ Sentinel: [CRITICAL] Fix Path Traversal Vulnerability in TypeScript Extractor#274

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

🛡️ Sentinel: [CRITICAL] Fix Path Traversal Vulnerability in TypeScript Extractor#274
bashandbone wants to merge 1 commit into
mainfrom
sentinel/fix-path-traversal-12719017417937973642

Conversation

@bashandbone
Copy link
Copy Markdown
Contributor

@bashandbone bashandbone commented May 29, 2026

🚨 Severity: CRITICAL

💡 Vulnerability: A path traversal vulnerability existed in the manual path normalization logic (.components()) of the TypeScript module extractor (crates/flow/src/incremental/extractors/typescript.rs). When the canonicalize fallback was triggered, the manual implementation simply called pop() on encountering a .. (ParentDir) component. This allowed malicious import paths with excessive ../ components to strip root (/) or prefix boundaries and inadvertently turn into relative paths or bypass intended base path confinement.

🎯 Impact: If an attacker controls or injects module specifiers, they could theoretically escape the intended analysis directory, causing the engine to resolve, read, and process arbitrary files on the host filesystem that the process has access to, leading to information disclosure.

🔧 Fix: Implemented robust and secure manual path normalization. The fix prevents popping when at the root or prefix (RootDir, Prefix) and ensures that ParentDir is correctly accumulated (push) if the resolved path is inherently relative and already walking up the tree, strictly imitating the safe behavior of canonicalize.

Verification:

  • Added a Sentinel journal entry reflecting this learning.
  • Verified fix logic using isolation testing.
  • cargo test -p thread-flow --test extractor_typescript_tests passes seamlessly without regressions.

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

Summary by Sourcery

Harden TypeScript dependency extractor path normalization to prevent path traversal beyond the intended root and document the vulnerability and its mitigation in Sentinel notes.

Bug Fixes:

  • Fix path traversal vulnerability in the TypeScript dependency extractor by safely handling ParentDir segments during manual path normalization.

Documentation:

  • Add a Sentinel journal entry documenting the path traversal vulnerability, its root cause, and safe normalization practices.

…t Extractor

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

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Fixes a critical path traversal vulnerability in the TypeScript dependency extractor by hardening manual path normalization behavior and adds a Sentinel journal entry documenting the issue and its prevention.

Flow diagram for updated ParentDir handling in manual path normalization

flowchart TD
    A[Iterate resolved.components] --> B{component is ParentDir?}
    B -- no --> C[components.push component]
    C --> A

    B -- yes --> D{components.is_empty or components.last is ParentDir?}
    D -- yes --> E[components.push ParentDir]
    E --> A

    D -- no --> F{components.last is RootDir or Prefix?}
    F -- yes --> G[[Ignore ParentDir]]
    G --> A

    F -- no --> H[components.pop]
    H --> A
Loading

File-Level Changes

Change Details Files
Harden manual path normalization for TypeScript dependency resolution to safely handle ParentDir components without escaping root or prefix boundaries.
  • Update the ParentDir handling logic in the manual component-based path normalization to avoid popping past root or prefix components.
  • Preserve ParentDir components when the accumulated component stack is empty or already ends with ParentDir, ensuring relative upward traversal is represented rather than collapsed away.
  • Maintain existing behavior for CurDir and other path components while operating on the same components vector.
crates/flow/src/incremental/extractors/typescript.rs
Add Sentinel documentation describing the path traversal vulnerability and the prevention strategy for manual path normalization.
  • Create a sentinel markdown note describing the discovered path traversal vulnerability in TypeScript module resolution.
  • Document the key learning about safe handling of ParentDir when canonicalization fails.
  • Record prevention guidance emphasizing not popping RootDir/Prefix and preserving ParentDir when at or beyond the root boundary.
.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 subtle; consider extracting it into a small helper function (e.g., normalize_parent_dir_component) or adding a short inline comment describing the intended invariants (when to push vs. ignore vs. pop) to make future maintenance and security review easier.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `ParentDir` handling logic is subtle; consider extracting it into a small helper function (e.g., `normalize_parent_dir_component`) or adding a short inline comment describing the intended invariants (when to push vs. ignore vs. pop) to make future maintenance and security review easier.

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 TypeScript/JavaScript dependency extractor’s fallback path normalization (when canonicalize() fails) to prevent .. segments from popping past RootDir/Prefix, avoiding incorrect normalization that could enable path traversal behaviors. Also adds a Sentinel journal entry documenting the vulnerability and mitigation.

Changes:

  • Update manual .components() normalization to avoid popping RootDir/Prefix and to preserve leading .. for inherently-relative paths.
  • Add a Sentinel journal entry describing the path traversal issue and safe normalization rules.

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 Hardens manual ParentDir handling during fallback normalization to prevent popping above root/prefix.
.jules/sentinel.md Documents the vulnerability, root cause, and prevention guidance in Sentinel notes.

💡 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-30 - Path Traversal in Manual Path Normalization
Comment on lines 810 to +814
std::path::Component::ParentDir => {
components.pop();
if components.is_empty() || components.last() == Some(&std::path::Component::ParentDir) {
components.push(std::path::Component::ParentDir);
} else if let Some(last) = components.last() {
match last {
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