Skip to content

🛡️ Sentinel: [HIGH] Fix path traversal vulnerability#249

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

🛡️ Sentinel: [HIGH] Fix path traversal vulnerability#249
bashandbone wants to merge 1 commit into
mainfrom
sentinel-path-traversal-fix-10142149368411894985

Conversation

@bashandbone
Copy link
Copy Markdown
Contributor

@bashandbone bashandbone commented May 20, 2026

🚨 Severity: HIGH
đź’ˇ Vulnerability: In crates/flow/src/incremental/extractors/typescript.rs, manual path normalization handled .. components by blindly calling components.pop(). This effectively meant ../ components could silently disappear or strip root path components.
🎯 Impact: This flaw breaks relative navigation and creates a path traversal vulnerability where ascensions (..) could escape intended root scopes or incorrectly simplify relative paths, leading to incorrect file access or bypassed path constraints.
đź”§ Fix: Updated the path canonicalization to properly implement lexical resolution. It now pushes .. if the path is empty or already ends in .. (preserving necessary ascensions), ignores .. if the path is at a root or prefix boundary (preventing traversal above root), and safely pops otherwise.
âś… Verification: Ran unit tests for the TypeScript extractor (cargo test -p thread-flow --test extractor_typescript_tests) which all pass successfully.


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

Summary by Sourcery

Fix unsafe path normalization in the TypeScript dependency extractor to prevent path traversal and document the vulnerability and its mitigation.

Bug Fixes:

  • Harden handling of parent directory components in the TypeScript dependency extractor to prevent escaping root or losing necessary ascensions during path normalization.

Documentation:

  • Add Sentinel documentation entry describing the lexical path normalization vulnerability, its impact, and the correct mitigation approach.

During lexical path normalization, `../` components were handled by blindly calling `components.pop()`. This allowed paths to escape intended root scopes by popping root indicators, or incorrectly simplified paths like `../../foo` into `foo` if the components list was empty. The manual path resolution has been updated to explicitly preserve `..` ascensions and prevent traversal beyond roots.

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

sourcery-ai Bot commented May 20, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refines manual path normalization in the TypeScript dependency extractor to apply correct lexical resolution for .. components, preventing traversal above root, and documents the vulnerability and its fix in Sentinel metadata.

File-Level Changes

Change Details Files
Harden lexical path canonicalization for .. components in the TypeScript dependency extractor to prevent path traversal above root and preserve valid ascensions.
  • Replace naive components.pop() handling for ParentDir with logic that inspects the last component before deciding to push, ignore, or pop.
  • Ensure ParentDir is preserved when the components stack is empty or already ends in ParentDir, maintaining relative ascensions.
  • Block ParentDir from popping RootDir or Prefix components to avoid escaping the intended root scope.
  • Keep behavior of ignoring CurDir and pushing other components unchanged.
crates/flow/src/incremental/extractors/typescript.rs
Document the path traversal vulnerability and the prevention pattern in Sentinel documentation.
  • Add a Sentinel markdown entry describing the original vulnerability in manual path normalization, its impact, and the new prevention rules.
  • Capture the specific guidance for safely handling ParentDir in lexical path normalization using std::path::Component.
.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 logic in the path normalization branch has become non-trivial; consider extracting it into a small helper function with a brief comment documenting the intended invariants (empty stack, root/prefix boundaries, chained ..) to improve readability and future maintenance.
  • For cross-platform clarity, it might be worth explicitly documenting how the Prefix and RootDir cases behave on Windows (e.g., UNC paths, drive prefixes) since the traversal blocking logic depends on these semantics.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `ParentDir` handling logic in the path normalization branch has become non-trivial; consider extracting it into a small helper function with a brief comment documenting the intended invariants (empty stack, root/prefix boundaries, chained `..`) to improve readability and future maintenance.
- For cross-platform clarity, it might be worth explicitly documenting how the `Prefix` and `RootDir` cases behave on Windows (e.g., UNC paths, drive prefixes) since the traversal blocking logic depends on these semantics.

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 hardens the TypeScript dependency extractor’s manual path normalization to avoid incorrectly dropping .. path components, addressing a reported path traversal/incorrect-resolution vulnerability. It also adds a Sentinel entry documenting the issue and prevention guidance.

Changes:

  • Update manual .. resolution logic in TypeScriptDependencyExtractor::resolve_module_path to preserve leading ascensions and prevent popping root boundaries.
  • Add a .jules/sentinel.md entry capturing the vulnerability details and mitigation guidance.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
crates/flow/src/incremental/extractors/typescript.rs Adjusts lexical handling of ParentDir components during manual path normalization.
.jules/sentinel.md Adds a Sentinel note describing the vulnerability and recommended prevention approach.

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

Comment on lines +816 to +817
Some(std::path::Component::RootDir)
| Some(std::path::Component::Prefix(_)) => {}
Comment on lines 802 to +815
// 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 => {
components.pop();
let last = components.last().copied();
match last {
None | Some(std::path::Component::ParentDir) => {
components.push(component);
}
Comment thread .jules/sentinel.md
Comment on lines +1 to +3

## 2024-05-20 - Lexical Path Normalization Traversal Vulnerability
**Vulnerability:** In `crates/flow/src/incremental/extractors/typescript.rs`, manual path normalization handled `..` components by blindly calling `components.pop()`.
Comment thread .jules/sentinel.md
@@ -0,0 +1,5 @@

## 2024-05-20 - Lexical Path Normalization Traversal Vulnerability
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