Skip to content

🛡️ Sentinel: [CRITICAL/HIGH] Fix path traversal in manual path resolution#202

Open
bashandbone wants to merge 1 commit intomainfrom
sentinel/fix-path-traversal-resolution-11042287032616640001
Open

🛡️ Sentinel: [CRITICAL/HIGH] Fix path traversal in manual path resolution#202
bashandbone wants to merge 1 commit intomainfrom
sentinel/fix-path-traversal-resolution-11042287032616640001

Conversation

@bashandbone
Copy link
Copy Markdown
Contributor

@bashandbone bashandbone commented May 7, 2026

🚨 Severity: HIGH
đź’ˇ Vulnerability: In crates/flow/src/incremental/extractors/typescript.rs, manual path resolution for imports popping std::path::Component::ParentDir (..) simply used components.pop(). This allows path traversal attacks, as it could pop RootDir or Prefix components, or discard existing consecutive .. components, bypassing the base directory and potentially allowing arbitrary file access on the host system.
🎯 Impact: An attacker could supply crafted import paths (e.g., ../../../etc/passwd) that escape the intended base directory and access sensitive files on the system or server.
đź”§ Fix: Explicitly check the last component before popping. If it's a RootDir or Prefix, do not pop. If the components list is empty or already ends in a ParentDir, correctly push the new ParentDir to preserve relative traversal properly.
âś… Verification: Ran cargo test -p thread-flow --test extractor_typescript_tests and cargo test --workspace to ensure no regressions and verify the path components logic handles standard operations safely.


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

Summary by Sourcery

Harden TypeScript import path resolution against path traversal while performing minor API and documentation cleanups.

Bug Fixes:

  • Prevent path traversal in manual TypeScript import path resolution by safely handling ParentDir components without popping root or prefix elements.

Enhancements:

  • Simplify rule-engine function signatures by removing unnecessary lifetimes and adjust minor formatting for readability in AST and rule-engine modules.

Documentation:

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

Copilot AI review requested due to automatic review settings May 7, 2026 18:26
@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
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 7, 2026

Reviewer's Guide

Fixes a high-severity path traversal in TypeScript import resolution by making ParentDir handling safe and adds a small set of style/ergonomic cleanups elsewhere, plus a Sentinel learning note.

Flow diagram for safe ParentDir handling in TypeScriptDependencyExtractor

flowchart TD
    A[Encounter Component::ParentDir] --> B{components.last exists?}
    B -- No --> C[Push Component::ParentDir onto components]
    B -- Yes --> D{last is RootDir or Prefix?}

    D -- Yes --> E[Do not pop
Keep components unchanged]
    D -- No --> F{last is ParentDir?}

    F -- Yes --> G[Push Component::ParentDir
Preserve leading ParentDirs]
    F -- No --> H[Pop last component
Navigate up one directory]

    style A fill:#fdf5e6,stroke:#333
    style C fill:#e6f7ff,stroke:#333
    style E fill:#ffe6e6,stroke:#333
    style G fill:#e6ffe6,stroke:#333
    style H fill:#e6ffe6,stroke:#333
Loading

File-Level Changes

Change Details Files
Harden manual path resolution against path traversal when processing ParentDir components in TypeScript dependency extraction.
  • Replace naive components.pop() on ParentDir with logic that inspects the last component before mutating the stack.
  • Prevent popping RootDir or Prefix components while resolving paths.
  • Ensure leading or consecutive ParentDir components are preserved by pushing ParentDir when the stack is empty or already ends with ParentDir.
  • Keep CurDir as a no-op and continue pushing all other components unchanged.
crates/flow/src/incremental/extractors/typescript.rs
Minor refactors and formatting cleanups in AST and rule engine code for readability and simpler signatures.
  • Reformat String::from_utf8 error handling into a single chained expression.
  • Reformat long assert_eq! and iterator/mapping chains into multi-line style for clarity.
  • Simplify lifetime usage in check_var_in_constraints and check_var_in_transform by taking non-lifetime-annotated references.
  • Condense RwLock read().unwrap_or_else(...) chaining into a single line while preserving behavior.
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 documentation capturing the vulnerability, root cause, and prevention guidance.
  • Create a Sentinel markdown entry describing the path traversal issue in manual path resolution.
  • Document why naive ParentDir popping is unsafe and how to validate path components safely.
.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:

  • In the new ParentDir handling logic, consider extracting the component-manipulation into a small helper function with a clear name (e.g. apply_parent_dir) so the control flow around RootDir, Prefix, and leading ParentDir cases is easier to understand and reuse if needed elsewhere.
  • The manual component handling currently distinguishes RootDir and Prefix but does not explicitly document how Windows-specific prefixes (e.g. UNC paths or drive letters) should behave; adding a short code comment describing the intended behavior for these cases will make future changes to this logic safer.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In the new `ParentDir` handling logic, consider extracting the component-manipulation into a small helper function with a clear name (e.g. `apply_parent_dir`) so the control flow around `RootDir`, `Prefix`, and leading `ParentDir` cases is easier to understand and reuse if needed elsewhere.
- The manual component handling currently distinguishes `RootDir` and `Prefix` but does not explicitly document how Windows-specific prefixes (e.g. UNC paths or drive letters) should behave; adding a short code comment describing the intended behavior for these cases will make future changes to this logic safer.

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/JavaScript dependency extractor’s fallback path normalization logic to avoid unsafe handling of .. (ParentDir) components during manual resolution, reducing the risk of path traversal via crafted import specifiers.

Changes:

  • Update manual .. resolution in TypeScriptDependencyExtractor::resolve_module_path to avoid popping RootDir/Prefix and to preserve consecutive/leading .. correctly.
  • Minor refactors/formatting adjustments in rule-engine and ast-engine modules (no intended behavior change).
  • Add a .jules/sentinel.md note documenting the issue and prevention guidance.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/rule-engine/src/rule/referent_rule.rs Minor formatting change in Registration::read (no logic change).
crates/rule-engine/src/rule/mod.rs Reformat defined_vars collection for readability.
crates/rule-engine/src/check_var.rs Simplify function signatures by removing unnecessary lifetimes.
crates/flow/src/incremental/extractors/typescript.rs Security fix: safer manual handling of ParentDir components during path normalization.
crates/ast-engine/src/tree_sitter/mod.rs Small formatting/refactor in UTF-8 conversion and a test assertion.
.jules/sentinel.md Add internal documentation describing the path traversal issue and mitigation.

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

Comment on lines +811 to +815
// 🛡️ Sentinel: Fix path traversal in manual path resolution
// Prevent popping RootDir or Prefix, and preserve leading ParentDirs
if let Some(last) = components.last() {
match last {
std::path::Component::RootDir
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