Skip to content

🛡️ Sentinel: [HIGH] Fix Path Traversal in TypeScript Module Resolution#290

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

🛡️ Sentinel: [HIGH] Fix Path Traversal in TypeScript Module Resolution#290
bashandbone wants to merge 1 commit into
mainfrom
sentinel-fix-path-traversal-10141229190092945309

Conversation

@bashandbone

@bashandbone bashandbone commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

🚨 Severity: HIGH
💡 Vulnerability: Path traversal vulnerability during manual path normalization in thread-flow's TypeScript module resolution. The manual fallback for path resolution incorrectly popped path components when encountering ParentDir (../) without checking if the previous component was a RootDir (/), Prefix (e.g., C:), or if the components list was empty, allowing path traversal outside the intended base directory.
🎯 Impact: An attacker could potentially resolve modules outside of the intended project root, leading to unauthorized file access or analysis of sensitive files outside the workspace.
🔧 Fix: When manually normalizing paths with std::path::Component, explicitly block Component::ParentDir from popping Component::RootDir or Component::Prefix. If the components list is empty or its last element is Component::ParentDir, the new Component::ParentDir is pushed rather than ignored to correctly preserve relative paths like ../../a.
Verification: Verified by running cargo test -p thread-flow --test extractor_typescript_tests and checking the entire workspace with cargo +nightly fmt and cargo clippy --workspace -- -D warnings.


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

Summary by Sourcery

Fix TypeScript module resolution to prevent path traversal outside the project root and make small refactors and documentation updates across related crates.

Bug Fixes:

  • Harden TypeScript dependency resolution so parent directory components cannot traverse beyond the root or drive prefix during manual path normalization.

Enhancements:

  • Simplify lifetimes in rule engine variable-check helpers by using non-generic reference parameters.
  • Apply minor code-style and readability adjustments in AST and rule engine modules.

Documentation:

  • Add a Sentinel security note documenting the discovered path traversal vulnerability, its cause, and the prevention strategy.

Update manual path resolution logic in `typescript.rs` to correctly
handle `Component::ParentDir`. Prevent popping past `RootDir` or
`Prefix`, and ensure `ParentDir` is pushed if the components list is
empty or its last element is `ParentDir`. Also adds a new journal
entry and elides needlessly explicit lifetimes found by `clippy`.

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 June 5, 2026 17:49
@sourcery-ai

sourcery-ai Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Fixes a path traversal vulnerability in the TypeScript dependency extractor’s manual path normalization while also applying minor refactors/formatting cleanups in AST and rule engine modules and adding a Sentinel incident note.

Flow diagram for updated ParentDir handling in TypeScript path normalization

flowchart TD
    A[Component is ParentDir] --> B{components.last}
    B -->|None| C[Push ParentDir onto components]
    B -->|ParentDir| C
    B -->|RootDir or Prefix| D[Do nothing]
    B -->|Other component| E[Pop last component from components]
Loading

File-Level Changes

Change Details Files
Harden manual path normalization in TypeScript module resolution to prevent path traversal outside the root directory.
  • Adjust handling of std::path::Component::ParentDir to avoid popping past RootDir or Prefix components.
  • Preserve leading ParentDir segments when there is no prior component or when the last component is also ParentDir, maintaining correct relative paths like ../../a.
  • Retain normal component pushing behavior for non-ParentDir, non-CurDir components and ignore CurDir components.
crates/flow/src/incremental/extractors/typescript.rs
Apply small refactors and formatting improvements in AST engine and rule engine to satisfy clippy/rustfmt and simplify code.
  • Simplify String::from_utf8 unwrap_or_else formatting in ContentExt implementation while preserving behavior.
  • Reformat long assert_eq! in tree-sitter tests across multiple lines for readability.
  • Remove unnecessary lifetime parameters from helper functions that operate on borrowed constraints/transform references in check_var.rs.
  • Reformat defined_vars mapping in Rule::Pattern variant for clarity and style compliance.
  • Inline read-lock unwrap_or_else chain in referent_rule::Registration::read for a more concise expression.
crates/ast-engine/src/tree_sitter/mod.rs
crates/rule-engine/src/check_var.rs
crates/rule-engine/src/rule/mod.rs
crates/rule-engine/src/rule/referent_rule.rs
Add Sentinel incident documentation for the discovered path traversal vulnerability and its mitigation.
  • Create .jules/sentinel.md capturing vulnerability description, root cause, and prevention guidance for future work.
.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 manual path normalization logic around Component::ParentDir is security-sensitive; consider extracting it into a small helper with clearly defined invariants so any future changes to module resolution reuse the same, vetted normalization behavior.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The manual path normalization logic around `Component::ParentDir` is security-sensitive; consider extracting it into a small helper with clearly defined invariants so any future changes to module resolution reuse the same, vetted normalization behavior.

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.

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

Pull request overview

This PR is primarily a security hardening change in thread-flow’s TypeScript module resolution to address a reported path traversal issue during manual path normalization, alongside small refactors/formatting adjustments and a new Sentinel note documenting the finding.

Changes:

  • Harden manual ../ normalization logic in TypeScript dependency resolution to avoid popping past RootDir/Prefix.
  • Small refactors/formatting tweaks in rule-engine and ast-engine.
  • Add a Sentinel security note documenting the vulnerability and prevention strategy.

Reviewed changes

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

Show a summary per file
File Description
crates/rule-engine/src/rule/referent_rule.rs Minor formatting change in Registration::read() implementation.
crates/rule-engine/src/rule/mod.rs Formatting-only change for readability in Rule::defined_vars().
crates/rule-engine/src/check_var.rs Simplify helper signatures by removing unnecessary lifetimes.
crates/flow/src/incremental/extractors/typescript.rs Update manual path normalization for ParentDir handling in TS module resolution.
crates/ast-engine/src/tree_sitter/mod.rs Small formatting/readability tweaks and test assertion formatting.
.jules/sentinel.md New Sentinel entry documenting the path traversal issue and mitigation approach.

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

Comment on lines 810 to +814
std::path::Component::ParentDir => {
components.pop();
// Prevent path traversal outside root
match components.last() {
Some(std::path::Component::ParentDir) | None => {
components.push(component);
Comment thread .jules/sentinel.md
@@ -0,0 +1,4 @@
## 2026-06-05 - [Path Traversal in Manual Path Normalization]
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