Skip to content

🛡️ Sentinel: [HIGH] Fix path traversal#288

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

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

Conversation

@bashandbone
Copy link
Copy Markdown
Contributor

@bashandbone bashandbone commented Jun 4, 2026

🚨 Severity: HIGH

💡 Vulnerability: A path traversal vulnerability existed in resolve_module_path in crates/flow/src/incremental/extractors/typescript.rs. When canonicalize failed, the fallback manual resolution blindly popped the last component off the stack when encountering .. (Component::ParentDir). This allowed an attacker to traverse above the root directory (e.g., /var/www/../../etc/passwd would pop RootDir and allow access to /etc/passwd).

🎯 Impact: If resolve_module_path is fed user-controlled import strings, an attacker could traverse outside the intended project directory, potentially accessing sensitive files.

🔧 Fix: Explicitly check the last path component before popping it. Block popping Component::RootDir or Component::Prefix. If the components list is empty or the last element is already Component::ParentDir, append the new ParentDir to safely handle relative paths like ../../.

Verification:

  1. Tests in extractor_typescript_tests.rs pass successfully (cargo test -p thread-flow --test extractor_typescript_tests).
  2. Run standard workspace validation: cargo +nightly fmt, cargo clippy --workspace -- -D warnings, and cargo test --workspace.

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

Summary by Sourcery

Harden TypeScript dependency path resolution against path traversal and perform minor API and formatting cleanups.

Bug Fixes:

  • Prevent path traversal above the project root when manually normalizing TypeScript module paths after canonicalization fails.

Enhancements:

  • Relax lifetime annotations on rule-engine variable checking helpers to use simpler reference types.
  • Tidy formatting and unwrap_or_else usage in AST engine and rule-engine modules for consistency.

Documentation:

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

Prevents `Component::ParentDir` from popping `RootDir` or `Prefix` and preserves consecutive relative paths.

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

sourcery-ai Bot commented Jun 4, 2026

Reviewer's Guide

Fixes a high-severity path traversal bug in TypeScript module resolution by hardening manual path normalization, while also performing small API cleanups and formatting changes across rule-engine and ast-engine modules and adding a Sentinel incident record.

File-Level Changes

Change Details Files
Harden manual path normalization in TypeScript dependency extractor to prevent traversing above root on .. components when canonicalize fails.
  • Adjust Component::ParentDir handling to inspect the last accumulated component before modifying the stack.
  • Disallow popping Component::RootDir and Component::Prefix when processing parent directory components.
  • Preserve chains of .. by appending ParentDir when the last component is already ParentDir or when the stack is empty, while still popping normal path segments.
crates/flow/src/incremental/extractors/typescript.rs
Tighten function signatures in variable checking utilities by removing unnecessary lifetimes from reference parameters.
  • Change constraints and transform parameters from &'r references to plain shared references in several rule-checking functions.
  • Update helper functions for checking variables in constraints and transforms to use lifetime-elided reference types.
crates/rule-engine/src/check_var.rs
Apply minor readability and style cleanups in AST engine and rule engine modules.
  • Reformat a String::from_utf8 / from_utf8_lossy fallback expression into a single, idiomatic chained call.
  • Expand an assertion comparing two tree-sitter S-expressions into multiline form for readability.
  • Reformat Rule::Pattern’s defined_vars implementation to a more readable multi-line iterator chain.
  • Simplify Registration::read’s lock-unwrapping expression into a single chained call.
crates/ast-engine/src/tree_sitter/mod.rs
crates/rule-engine/src/rule/mod.rs
crates/rule-engine/src/rule/referent_rule.rs
Record the security incident and remediation guidance for future reference in Sentinel documentation.
  • Add a Sentinel markdown entry describing the path traversal vulnerability, its root cause, and safe handling patterns for Component::ParentDir.
  • Document preventative guidelines for path normalization to avoid popping root or prefix components and to correctly handle consecutive .. segments.
.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

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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 in resolve_module_path is correct but fairly nested; consider extracting this normalization into a small helper function (e.g., push_component_safely(&mut components, component)) to make the control-flow and invariants around RootDir/Prefix/ParentDir clearer and easier to reason about.
  • If the intent is to keep resolutions within a specific project root rather than just the filesystem root, you may want to enforce a logical base directory (e.g., stop accepting additional ParentDir components once you are at the project root) instead of only preventing pops past RootDir/Prefix, so callers can’t escape the project tree via deeply nested ../../ sequences.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `ParentDir` handling in `resolve_module_path` is correct but fairly nested; consider extracting this normalization into a small helper function (e.g., `push_component_safely(&mut components, component)`) to make the control-flow and invariants around `RootDir`/`Prefix`/`ParentDir` clearer and easier to reason about.
- If the intent is to keep resolutions within a specific project root rather than just the filesystem root, you may want to enforce a logical base directory (e.g., stop accepting additional `ParentDir` components once you are at the project root) instead of only preventing pops past `RootDir`/`Prefix`, so callers can’t escape the project tree via deeply nested `../../` sequences.

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.

2 participants