Skip to content

πŸ›‘οΈ Sentinel: [CRITICAL] Fix Path Traversal in TypeScript Extractor#299

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

πŸ›‘οΈ Sentinel: [CRITICAL] Fix Path Traversal in TypeScript Extractor#299
bashandbone wants to merge 1 commit into
mainfrom
sentinel-fix-path-traversal-5219326069465249508

Conversation

@bashandbone

@bashandbone bashandbone commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

🚨 Severity: CRITICAL
πŸ’‘ Vulnerability: Component::ParentDir incorrectly handles root directories and empty components lists, allowing path traversal attacks via incorrect manual normalization.
🎯 Impact: An attacker could bypass path restrictions or construct malicious relative paths (../../) escaping intended directories during module resolution.
πŸ”§ Fix: Implemented safe path component popping that preserves roots/prefixes and pushes parent dirs for relative paths.
βœ… Verification: Run cargo test to verify behavior.


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

Summary by Sourcery

Harden path normalization in the TypeScript dependency extractor to prevent path traversal while making minor formatting and documentation updates.

Bug Fixes:

  • Prevent path traversal by ensuring parent directory components do not pop root/prefix components and are preserved appropriately for relative paths in the TypeScript extractor.

Enhancements:

  • Apply minor code formatting cleanups in AST and rule engine modules for consistency.

Documentation:

  • Add a Sentinel security note documenting the insecure path normalization issue, its root cause, and preventative 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.

@sourcery-ai

sourcery-ai Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Fixes insecure manual path normalization in the TypeScript dependency extractor by making ParentDir handling root-aware and preserving relative traversals, and includes minor formatting/cleanup changes elsewhere plus a Sentinel incident note.

File-Level Changes

Change Details Files
Harden ParentDir handling during TypeScript path normalization to prevent path traversal and correctly preserve relative .. components.
  • Change ParentDir logic to inspect the last accumulated component before popping.
  • Disallow popping when the last component is RootDir or Prefix, preserving roots/prefixes.
  • When the last component is ParentDir, push another ParentDir instead of popping to keep ../../ style traversals.
  • When there are no prior components, push ParentDir so leading .. are preserved.
  • Leave handling of CurDir and other components unchanged (CurDir ignored, others pushed).
crates/flow/src/incremental/extractors/typescript.rs
Apply minor refactors and formatting cleanups in AST and rule engine code.
  • Reformat chained unwrap_or_else() for String::from_utf8 to a single multi-line expression without behavior changes.
  • Reformat a long assert_eq! comparing Tree-sitter S-expressions into a multi-line assertion.
  • Reformat Rule::Pattern defined_vars collection into a multi-line iterator chain for readability.
  • Inline the unwrap_or_else() call on RwLock::read() in Registration::read() without changing semantics.
crates/ast-engine/src/tree_sitter/mod.rs
crates/rule-engine/src/rule/mod.rs
crates/rule-engine/src/rule/referent_rule.rs
Add Sentinel security incident documentation for the path normalization vulnerability.
  • Document the original ParentDir handling vulnerability, including empty list and root/prefix issues.
  • Capture key learning about pitfalls of manual path normalization.
  • Record prevention guidance to block popping RootDir/Prefix and to push ParentDir when appropriate.
.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

@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 new Component::ParentDir handling logic in the TypeScript extractor is fairly intricate; consider extracting it into a small helper (e.g., fn push_parent_dir(components: &mut Vec<Component>)) with a brief doc comment so the invariants around roots/prefixes and accumulated .. segments are easier to reason about and reuse consistently.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `Component::ParentDir` handling logic in the TypeScript extractor is fairly intricate; consider extracting it into a small helper (e.g., `fn push_parent_dir(components: &mut Vec<Component>)`) with a brief doc comment so the invariants around roots/prefixes and accumulated `..` segments are easier to reason about and reuse consistently.

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 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.

1 participant