🛡️ Sentinel: [CRITICAL/HIGH] Fix path traversal in TypeScript extraction#304
Conversation
In `crates/flow/src/incremental/extractors/typescript.rs`, manual path normalization failed to correctly handle out-of-bounds `../` (ParentDir) references. When resolving paths outside the base tree, it would mistakenly pop `ParentDir` blindly or ignore it if the component list was empty. This update explicitly handles `std::path::Component::ParentDir`. If the component list is empty or the last component is `ParentDir`, we safely push it to preserve the traversal instead of swallowing it. Additionally, it blocks popping `RootDir` or `Prefix` elements to prevent arbitrary escapes. Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
|
đź‘‹ 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Reviewer's GuideFixes a critical path traversal bug in the TypeScript dependency extractor’s manual path normalization by correctly handling ParentDir components and root boundaries, plus some minor refactors/formatting changes in AST and rule-engine code and adds a Sentinel incident note. Flow diagram for updated ParentDir handling in TypeScript dependency extractionflowchart TD
A[Component is ParentDir] --> B{components is empty?}
B -- Yes --> C[Push ParentDir onto components]
B -- No --> D[Get last component]
D --> E{last is ParentDir?}
E -- Yes --> F[Push ParentDir onto components]
E -- No --> G{last is RootDir or Prefix?}
G -- Yes --> H[Do nothing]
G -- No --> I[Pop last component from components]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In the
ParentDirhandling in the TypeScript extractor, the branch where the last component isRootDirorPrefixcurrently drops theParentDirentirely; this seems to conflict with the sentinel note about preserving out-of-bounds..components—consider either explicitly documenting this choice or pushing aParentDirin those cases if you truly want to track traversal above the base. - The new
ParentDirnormalization logic is fairly intricate; consider extracting it into a small helper (e.g.,fn push_parent_dir(components: &mut Vec<Component>)) so its edge-case behavior (empty stack, stackedParentDir,RootDir/Prefix) is easier to read and reason about.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In the `ParentDir` handling in the TypeScript extractor, the branch where the last component is `RootDir` or `Prefix` currently drops the `ParentDir` entirely; this seems to conflict with the sentinel note about preserving out-of-bounds `..` components—consider either explicitly documenting this choice or pushing a `ParentDir` in those cases if you truly want to track traversal above the base.
- The new `ParentDir` normalization logic is fairly intricate; consider extracting it into a small helper (e.g., `fn push_parent_dir(components: &mut Vec<Component>)`) so its edge-case behavior (empty stack, stacked `ParentDir`, `RootDir`/`Prefix`) is easier to read and reason about.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
🚨 Severity: CRITICAL/HIGH
đź’ˇ Vulnerability: Path Traversal in TypeScript dependency extraction. When manually normalizing imported modules that escape the base directory (e.g.
../../../), the logic poppedParentDirunrestrictedly or discarded it, which could trick the resolution system into incorrectly interpreting file locations and subverting later bounds checks.🎯 Impact: A maliciously crafted project or dependency tree could force the extraction engine to resolve logic, cache invalidation hashes, or access structures pointing to arbitrary files on the execution system inside the thread processing boundaries if standard canonicalization bypassed them.
đź”§ Fix: Updated
Component::ParentDirbehavior insideresolved.components()to check if the path is empty or already ends inParentDir. In those cases, it safely pushesParentDir. It also blocks poppingRootDirandPrefix.âś… Verification: Run
cargo test -p thread-flow --test extractor_typescript_testsand ensure the code changes cause no side-effects and that relative components are correctly persisted out-of-bounds.PR created automatically by Jules for task 13687102911898330852 started by @bashandbone
Summary by Sourcery
Harden TypeScript dependency path resolution against parent-directory traversal and make minor code cleanups across AST and rule engine modules.
Bug Fixes:
Enhancements:
Documentation:
Chores: