Skip to content

🛡️ Sentinel: [HIGH] Fix path traversal in manual TS module path resolution#161

Open
bashandbone wants to merge 1 commit intomainfrom
sentinel-fix-path-traversal-resolution-16283416882480453920
Open

🛡️ Sentinel: [HIGH] Fix path traversal in manual TS module path resolution#161
bashandbone wants to merge 1 commit intomainfrom
sentinel-fix-path-traversal-resolution-16283416882480453920

Conversation

@bashandbone
Copy link
Copy Markdown
Contributor

@bashandbone bashandbone commented Apr 19, 2026

🚨 Severity: HIGH
💡 Vulnerability: A path traversal vulnerability existed in the manual path normalization fallback logic within TypeScriptDependencyExtractor::resolve_module_path in crates/flow/src/incremental/extractors/typescript.rs. The logic used components.pop() incorrectly when encountering std::path::Component::ParentDir. If it was passed consecutive .. directories, or paths leading back up out of the virtual resolution root, it could either mistakenly ignore them entirely, or it could pop RootDir and Prefix components, effectively breaking out of intended boundaries.
🎯 Impact: It could cause incorrect relative module resolution, either masking dependencies, creating erroneous dependency edges outside of the project folder structure, or in specific cases exposing the internal path structure.
🔧 Fix: Updated the component reduction logic to push ParentDir onto the vector if the vector is empty, if the previous component was a ParentDir, and prevented popping if the previous component was a RootDir or Prefix.
✅ Verification: Ran cargo test -p thread-flow unit tests and standard incremental tests successfully without regression.


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

Summary by Sourcery

Fix TypeScript dependency extraction path normalization to prevent path traversal and document the vulnerability in Sentinel notes.

Bug Fixes:

  • Correct manual path normalization for TypeScript module resolution to safely handle parent directory components without escaping the intended root.

Documentation:

  • Add Sentinel security note documenting the path traversal vulnerability, its root cause, and prevention guidelines.

The `TypeScriptDependencyExtractor::resolve_module_path` manual fallback path normalization previously failed to correctly handle `ParentDir` (i.e. `..`) traversal limits, potentially allowing a path to erroneously escape its virtual root context or discard absolute prefixes incorrectly if it encountered consecutive `..` components. This update implements safer boundary checks.

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 April 19, 2026 17:29
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Apr 19, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts manual TypeScript module path normalization to safely handle ParentDir components and prevent path traversal, and documents the vulnerability and fix in a Sentinel note.

Flow diagram for updated ParentDir handling in resolve_module_path normalization

flowchart TD
    A[Start processing component] --> B{component is ParentDir?}
    B -->|No| C[If CurDir: do nothing<br/>Else: push component onto components]
    C --> Z[Next path component]

    B -->|Yes| D[Compute flags<br/>is_empty = components.is_empty<br/>last_is_parent = last == ParentDir<br/>last_is_root_or_prefix = last == RootDir or Prefix]

    D --> E{is_empty or last_is_parent?}
    E -->|Yes| F[Push ParentDir onto components]
    F --> Z

    E -->|No| G{last_is_root_or_prefix?}
    G -->|Yes| H[Do not pop components<br/>Leave components unchanged]
    H --> Z

    G -->|No| I[Pop last component from components]
    I --> Z

    Z --> J{More components?}
    J -->|Yes| A
    J -->|No| K[Finish normalization]
Loading

File-Level Changes

Change Details Files
Harden manual path normalization logic when handling .. (ParentDir) components during TypeScript module path resolution.
  • Replace unconditional components.pop() on ParentDir with guarded logic that examines the current components stack.
  • Preserve leading and consecutive ParentDir components by pushing them when the stack is empty or when the last component is also ParentDir.
  • Prevent popping RootDir or Prefix components when processing ParentDir to avoid escaping virtual roots or altering absolute paths.
crates/flow/src/incremental/extractors/typescript.rs
Add Sentinel documentation for the path traversal vulnerability and its remediation.
  • Create a Sentinel markdown file documenting the discovered manual path traversal vulnerability in TypeScript module resolution.
  • Describe the learning around correct handling of ParentDir, RootDir, and Prefix components in path normalization and how to prevent regressions.
.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 enough that it would benefit from a short comment explaining the intended invariants (e.g., when .. should be preserved vs. collapsed and why RootDir/Prefix are never popped) to aid future maintainers.
  • Consider factoring the ParentDir normalization into a small helper function (e.g., fn push_parent_dir(components: &mut Vec<Component>)) to encapsulate the rules around empty vectors, consecutive ParentDir, and RootDir/Prefix, which will make the main loop easier to read and reason about.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `ParentDir` handling logic is subtle enough that it would benefit from a short comment explaining the intended invariants (e.g., when `..` should be preserved vs. collapsed and why `RootDir`/`Prefix` are never popped) to aid future maintainers.
- Consider factoring the `ParentDir` normalization into a small helper function (e.g., `fn push_parent_dir(components: &mut Vec<Component>)`) to encapsulate the rules around empty vectors, consecutive `ParentDir`, and `RootDir`/`Prefix`, which will make the main loop easier to read and reason about.

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/canonicalization bug in the TypeScript extractor’s manual module path normalization fallback, and documents the vulnerability/learning in the Jules Sentinel log.

Changes:

  • Harden manual .. component reduction in TypeScriptDependencyExtractor::resolve_module_path to preserve leading/consecutive .. and avoid popping RootDir/Prefix.
  • Add a Sentinel entry describing the vulnerability 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 Updates manual path component reduction logic for .. during TS module resolution fallback.
.jules/sentinel.md Adds a security note documenting the issue and mitigation guidance.

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

Comment on lines +812 to +815
let last_is_parent = matches!(components.last(), Some(std::path::Component::ParentDir));
let last_is_root_or_prefix = matches!(
components.last(),
Some(std::path::Component::RootDir) | Some(std::path::Component::Prefix(_))
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

components.last() returns Option<&std::path::Component>, but the matches! patterns here are written as if they were matching Option<std::path::Component>. This is likely a compile error (and will also be caught by clippy). Update the patterns to match references (e.g., Some(&Component::ParentDir) / Some(&Component::RootDir) / Some(&Component::Prefix(_))) or bind components.last() to a variable and match on *last/last appropriately.

Suggested change
let last_is_parent = matches!(components.last(), Some(std::path::Component::ParentDir));
let last_is_root_or_prefix = matches!(
components.last(),
Some(std::path::Component::RootDir) | Some(std::path::Component::Prefix(_))
let last_is_parent =
matches!(components.last(), Some(&std::path::Component::ParentDir));
let last_is_root_or_prefix = matches!(
components.last(),
Some(&std::path::Component::RootDir)
| Some(&std::path::Component::Prefix(_))

Copilot uses AI. Check for mistakes.
Comment on lines +818 to +822
if is_empty || last_is_parent {
components.push(component);
} else if !last_is_root_or_prefix {
components.pop();
}
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change fixes tricky .. normalization edge cases, but there are no tests covering the newly handled scenarios (leading ../../... that should remain relative, and .. following RootDir/Prefix that must not pop them). Please add unit tests exercising these cases so the security fix can’t regress silently; the existing resolve_module_path tests in crates/flow/tests/extractor_typescript_tests.rs can be extended with a couple of dedicated cases.

Copilot uses AI. Check for mistakes.
Comment thread .jules/sentinel.md
Comment on lines +1 to +4
## 2025-05-15 - [Path Traversal in Manual Path Normalization]
**Vulnerability:** Manual path resolution using `components.pop()` on `std::path::Component::ParentDir` allowed path traversal. If a path like `../../a` was parsed, `components.pop()` on an empty `Vec` did nothing, turning the path into `a` instead of preserving the parent traversal. It could also pop `RootDir` or `Prefix` components, changing absolute paths to relative ones or traversing beyond intended roots.
**Learning:** `std::path::Component` normalization must handle empty lists and consecutive `ParentDir` components by pushing them instead of ignoring them. It must also explicitly avoid popping `RootDir` or `Prefix` components to prevent escaping virtual file systems or simulated root directories.
**Prevention:** Explicitly check if the `components` list is empty, if the last component is `ParentDir`, or if the last component is `RootDir` / `Prefix` before calling `pop()`.
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New markdown files in this repo typically include an SPDX header (often via an HTML comment block) or are covered by a REUSE.toml annotation. This file currently has no SPDX metadata and appears not to be covered by the existing REUSE.toml annotations, which can cause the fsfe/reuse-action CI job to fail. Add an SPDX header to this file or extend REUSE.toml to cover .jules/**.

Copilot uses AI. Check for mistakes.
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