🛡️ Sentinel: [HIGH] Fix path traversal#288
Conversation
Prevents `Component::ParentDir` from popping `RootDir` or `Prefix` and preserves consecutive relative paths. 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 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
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:
- The new
ParentDirhandling inresolve_module_pathis 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 aroundRootDir/Prefix/ParentDirclearer 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
ParentDircomponents once you are at the project root) instead of only preventing pops pastRootDir/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.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
🚨 Severity: HIGH
💡 Vulnerability: A path traversal vulnerability existed in
resolve_module_pathincrates/flow/src/incremental/extractors/typescript.rs. Whencanonicalizefailed, 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/passwdwould popRootDirand allow access to/etc/passwd).🎯 Impact: If
resolve_module_pathis 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::RootDirorComponent::Prefix. If the components list is empty or the last element is alreadyComponent::ParentDir, append the newParentDirto safely handle relative paths like../../.✅ Verification:
extractor_typescript_tests.rspass successfully (cargo test -p thread-flow --test extractor_typescript_tests).cargo +nightly fmt,cargo clippy --workspace -- -D warnings, andcargo 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:
Enhancements:
Documentation: