Skip to content
This repository was archived by the owner on Jun 16, 2026. It is now read-only.

🛡️ Sentinel: [CRITICAL] Fix path traversal#313

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

🛡️ Sentinel: [CRITICAL] Fix path traversal#313
bashandbone wants to merge 1 commit into
mainfrom
sentinel-fix-path-traversal-907347045678852346

Conversation

@bashandbone

@bashandbone bashandbone commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

🚨 Severity: CRITICAL
💡 Vulnerability: A path traversal vulnerability existed in crates/flow/src/incremental/extractors/typescript.rs during manual resolution of unresolved ../ paths. The code blindly popped components when encountering std::path::Component::ParentDir, which could erroneously pop root directories (RootDir) or prefixes (Prefix), or wrongly collapse ../.. components.
🎯 Impact: This could allow malicious or poorly-formed import specifiers to escape the intended project boundary or resolve to incorrect arbitrary paths on the file system, bypassing boundary constraints.
🔧 Fix: Modified the normalization logic to safely handle Component::ParentDir. It now explicitly checks the preceding component. It only pops if the last component is Normal. Otherwise, it pushes the ParentDir to preserve paths correctly.
✅ Verification: Ran formatting, linting, and specifically the extractor_typescript_tests which passed successfully. Added an entry to .jules/sentinel.md documenting this security learning.


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

Summary by Sourcery

Fix path traversal vulnerability in TypeScript dependency extraction and make minor ergonomic and documentation updates.

Bug Fixes:

  • Prevent unsafe popping of path components when normalizing TypeScript import paths to avoid path traversal outside project boundaries.

Enhancements:

  • Simplify lifetimes by using shared references for constraint and transform parameters in rule checking utilities.
  • Tidy string handling, rule variable extraction, and registration map access for improved readability and robustness.

Documentation:

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

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.

@sourcery-ai

sourcery-ai Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Fixes a critical path traversal vulnerability in the TypeScript incremental extractor by hardening manual path normalization, alongside small API ergonomics and formatting cleanups in the rule engine, AST engine, and tests, plus adding a Sentinel security learning note.

Flow diagram for updated ParentDir path normalization in TypeScriptDependencyExtractor

flowchart TD
    A["Component::ParentDir encountered"] --> B{"components.last() is Some(Component::Normal)"}
    B -->|yes| C["components.pop()"]
    B -->|no| D["components.push(Component::ParentDir)"]
    C --> E["continue components() iteration"]
    D --> E["continue components() iteration"]
Loading

File-Level Changes

Change Details Files
Harden manual path normalization in the TypeScript dependency extractor to prevent path traversal.
  • Update handling of std::path::Component::ParentDir when canonicalization fails to only pop a component if the last element is a Normal component
  • Preserve ParentDir components when there is no safe component to pop, ensuring sequences like ../../foo are not collapsed incorrectly
  • Document the vulnerability, root cause, and prevention guidelines in Sentinel security notes
crates/flow/src/incremental/extractors/typescript.rs
.jules/sentinel.md
Tidy rule engine APIs and formatting without changing behavior.
  • Remove unnecessary lifetime parameters from check_var helper functions and take constraints/transform as plain references
  • Reformat Rule::defined_vars implementation for readability
  • Simplify Registration::read by collapsing chained unwrap_or_else and clone calls onto a single line
crates/rule-engine/src/check_var.rs
crates/rule-engine/src/rule/mod.rs
crates/rule-engine/src/rule/referent_rule.rs
Minor readability and style improvements in AST engine string replacement and tests.
  • Reformat UTF-8 recovery logic in ContentExt::replace_range preserving behavior
  • Reformat a tree-sitter test assertion into multi-line form for clarity
crates/ast-engine/src/tree_sitter/mod.rs

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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

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 change in typescript.rs is an improvement, but you may want to make the behavior for root/prefix components explicit (e.g., match on RootDir/Prefix and document why they are never popped) so the security invariants are obvious and future refactors don’t unintentionally change them.
  • Consider extracting the manual path normalization logic into a small helper function with a clear contract (e.g., "never escape root or prefix, preserve leading ../ segments") so its behavior is easier to reason about and reuse in other places that might need similar traversal protection.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `ParentDir` handling change in `typescript.rs` is an improvement, but you may want to make the behavior for root/prefix components explicit (e.g., match on `RootDir`/`Prefix` and document why they are never popped) so the security invariants are obvious and future refactors don’t unintentionally change them.
- Consider extracting the manual path normalization logic into a small helper function with a clear contract (e.g., "never escape root or prefix, preserve leading ../ segments") so its behavior is easier to reason about and reuse in other places that might need similar traversal protection.

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant