Skip to content

πŸ›‘οΈ Sentinel: [CRITICAL/HIGH] Fix path traversal normalization bug#302

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

πŸ›‘οΈ Sentinel: [CRITICAL/HIGH] Fix path traversal normalization bug#302
bashandbone wants to merge 1 commit into
mainfrom
sentinel-fix-path-traversal-4834465002024166172

Conversation

@bashandbone

@bashandbone bashandbone commented Jun 9, 2026

Copy link
Copy Markdown
Contributor
  • 🚨 Severity: HIGH
  • πŸ’‘ Vulnerability: Component::ParentDir ignored when popping from an empty path buffer.
  • 🎯 Impact: Allows incorrect path resolution and bypasses relative directory boundaries.
  • πŸ”§ Fix: Implemented secure ParentDir handling.
  • βœ… Verification: Run cargo test -p thread-flow --test extractor_typescript_tests.

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

Summary by Sourcery

Harden TypeScript path normalization to correctly handle parent directory components and prevent traversal beyond expected bounds.

Bug Fixes:

  • Fix path component normalization to retain or handle leading and consecutive parent directory segments instead of silently discarding them.

Enhancements:

  • Relax unnecessary lifetime annotations on rule checking helpers to simplify signatures.
  • Minor formatting and readability improvements across rule-engine and AST modules.

Documentation:

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

Tests:

  • Simplify an integration test assertion in the D1 cache tests without changing behavior.

Fixes a path normalization issue where popping components naively allowed relative traversals (`../`) to be silently ignored when reaching the root or when stacking multiple traversals, potentially bypassing bounds checks.

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 9, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Fixes a HIGH-severity path traversal normalization bug in the TypeScript dependency extractor by making ParentDir handling safe when the path buffer is empty or contains prior ParentDir components, and includes several small refactors and formatting cleanups in the rule engine, AST engine, and tests.

Flow diagram for secure ParentDir path normalization in TypeScript dependency extractor

flowchart TD
    A[Start normalization over resolved.components] --> B[Iterate component]
    B --> C{component kind}

    C -->|ParentDir| D{last in components}
    D -->|RootDir or Prefix| E[Leave components unchanged]
    D -->|ParentDir or None| F[Push ParentDir into components]
    D -->|Other| G[Pop last component]

    C -->|CurDir| H[Skip component]
    C -->|Other segment| I[Push component into components]

    E --> J[Next component]
    F --> J
    G --> J
    H --> J
    I --> J
    J --> B

    B -->|no more components| K[Build normalized path from components]
Loading

File-Level Changes

Change Details Files
Harden path normalization in the TypeScript dependency extractor to correctly handle ParentDir components without dropping leading ".." segments.
  • Replace unconditional components.pop() on ParentDir with logic that inspects the last component before deciding whether to pop, ignore, or push the ParentDir
  • Ensure that ParentDir components are preserved when preceding components are RootDir, Prefix, another ParentDir, or the buffer is empty, preventing incorrect collapsing of leading ".."
crates/flow/src/incremental/extractors/typescript.rs
Tighten lifetimes and borrowing in rule variable checking helpers so parameters are plain shared references instead of references with explicit lifetimes.
  • Update signatures of check_rule_with_hint, check_vars_in_rewriter, check_vars, check_var_in_constraints, and check_var_in_transform to take &RapidMap and &Option without explicit lifetime parameters
  • Remove unused lifetime parameter from check_var_in_constraints and check_var_in_transform
crates/rule-engine/src/check_var.rs
Minor readability and style cleanups in rule/AST code and tests with no behavioral changes.
  • Reformat defined_vars implementation for Rule::Pattern to a multi-line chain for clarity
  • Simplify Registration::read to a single expression using unwrap_or_else on the read lock
  • Reformat ContentExt::apply_edit error-handling expression for String::from_utf8 to a single chained expression
  • Reformat a tree-sitter test assertion into a multi-line assert_eq!
  • Remove a no-op assert!(true, ...) in D1 cache integration tests
crates/rule-engine/src/rule/mod.rs
crates/rule-engine/src/rule/referent_rule.rs
crates/ast-engine/src/tree_sitter/mod.rs
crates/flow/tests/d1_cache_integration.rs
Document the path traversal normalization vulnerability and its fix for future reference.
  • Add a Sentinel security note describing the ParentDir handling bug, impact, and prevention guidance
.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 found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="crates/flow/tests/d1_cache_integration.rs" line_range="171-174" />
<code_context>
         .expect("Failed to create context without caching");

         // Should compile and work without cache field
-        assert!(
-            true,
-            "D1ExportContext created successfully without caching feature"
-        );
     }
 }
</code_context>
<issue_to_address>
**issue (testing):** Add regression tests for the TypeScript path normalization `ParentDir` handling fix.

This change alters security-relevant `ParentDir` handling in `TypeScriptDependencyExtractor`, but there are no tests covering the new behavior. Please extend the `thread-flow` TypeScript extractor tests (e.g. `extractor_typescript_tests`) to cover:
- Attempts to traverse above root/prefix (e.g. `/../foo`, `C:\..\bar`), ensuring we don’t pop past the root/prefix.
- Multiple/leading `ParentDir` components (`../foo`, `../../bar`, `foo/../../baz`).
- Mixed `CurDir`/`ParentDir` sequences (`./../foo`, `foo/./../bar`).
- Cases where `ParentDir` appears before vs. after a pushed `RootDir`/`Prefix`.
These should fail with the old implementation and pass with the new one to lock in the fix.
</issue_to_address>

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.

Comment on lines -171 to -174
assert!(
true,
"D1ExportContext created successfully without caching feature"
);

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.

issue (testing): Add regression tests for the TypeScript path normalization ParentDir handling fix.

This change alters security-relevant ParentDir handling in TypeScriptDependencyExtractor, but there are no tests covering the new behavior. Please extend the thread-flow TypeScript extractor tests (e.g. extractor_typescript_tests) to cover:

  • Attempts to traverse above root/prefix (e.g. /../foo, C:\..\bar), ensuring we don’t pop past the root/prefix.
  • Multiple/leading ParentDir components (../foo, ../../bar, foo/../../baz).
  • Mixed CurDir/ParentDir sequences (./../foo, foo/./../bar).
  • Cases where ParentDir appears before vs. after a pushed RootDir/Prefix.
    These should fail with the old implementation and pass with the new one to lock in the fix.

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