🛡️ Sentinel: [HIGH] Fix path traversal in path normalization#296
🛡️ Sentinel: [HIGH] Fix path traversal in path normalization#296bashandbone wants to merge 1 commit into
Conversation
Fixes a path traversal vulnerability in `TypeScriptDependencyExtractor` where malicious or malformed import paths containing `..` (`ParentDir`) components could inadvertently bypass directory boundaries by popping root or prefix path components due to an indiscriminate `components.pop()` implementation. The path normalization logic is now defensive and explicitly preserves root and prefix constraints. 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 the TypeScript dependency extractor’s custom path normalization by guarding against popping root/prefix components, along with minor refactors/formatting and documentation updates in rule/AST engine code and the security sentinel log. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Pull request overview
This PR aims to remediate a high-severity path normalization/path traversal issue in the TypeScript dependency extractor by preventing .. (Component::ParentDir) handling from popping past filesystem roots/prefixes, and includes a few small formatting/signature cleanups plus an incident note in .jules.
Changes:
- Harden manual path normalization in
TypeScriptDependencyExtractor::resolve_module_pathto avoid poppingRootDir/ WindowsPrefixwhen encounteringParentDir. - Minor readability refactors in
rule-engine(formatting and lifetime elision). - Add a short incident/prevention write-up in
.jules/sentinel.md.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/rule-engine/src/rule/referent_rule.rs | Collapses a multi-line lock/read/clone sequence into a single line. |
| crates/rule-engine/src/rule/mod.rs | Reformats defined_vars() collection for readability. |
| crates/rule-engine/src/check_var.rs | Simplifies helper signatures by removing unnecessary explicit lifetimes. |
| crates/flow/src/incremental/extractors/typescript.rs | Updates ParentDir handling to preserve root/prefix during manual normalization. |
| crates/ast-engine/src/tree_sitter/mod.rs | Minor formatting cleanup in UTF-8 recovery and an assertion. |
| .jules/sentinel.md | Adds documentation describing the incident and prevention guidance. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| std::path::Component::ParentDir => match components.last() { | ||
| Some(std::path::Component::RootDir) | ||
| | Some(std::path::Component::Prefix(_)) => {} | ||
| Some(std::path::Component::Normal(_)) => { | ||
| components.pop(); | ||
| } | ||
| _ => components.push(component), | ||
| }, |
| std::path::Component::ParentDir => match components.last() { | ||
| Some(std::path::Component::RootDir) | ||
| | Some(std::path::Component::Prefix(_)) => {} |
| ## 2025-02-24 - Path Traversal in Path Normalization | ||
| **Vulnerability:** Path traversal vulnerability in TypeScript module resolution where resolving paths with multiple `..` components could pop `RootDir` or `Prefix` components due to indiscriminate `components.pop()`. | ||
| **Learning:** Manual path normalization logic using `std::path::Component` needs to handle edge cases explicitly, such as stopping `ParentDir` components from popping root or prefix components, and correctly handling multiple `..` components when at the root or start of a relative path. | ||
| **Prevention:** Always check `components.last()` when popping for `ParentDir` and preserve root, prefix, and leading `ParentDir` components. Use established and safe normalization utilities where possible. |
🚨 Severity: HIGH
💡 Vulnerability: The custom path normalization loop in the
TypeScriptDependencyExtractorwould inadvertently popRootDir(e.g./) orPrefix(e.g.C:\) from the underlying path buffer when given..(std::path::Component::ParentDir). This could allow an attacker or malicious repository to specify module imports that traverse completely outside the intended project constraints.🎯 Impact: This allowed unauthorized path traversal across system boundaries by circumventing root limitations through maliciously formatted
../statements, resulting in potentially unintended system file resolutions and extraction leaks.🔧 Fix: Updated the
std::path::Component::ParentDirmatching logic to match againstcomponents.last(), explicitly guarding against poppingRootDirandPrefixwhile accumulating relative parent directors properly.✅ Verification: Ensure tests pass via
cargo test -p thread-flowand note thattest_path.rswas removed to not pollute git history.PR created automatically by Jules for task 10230978156132911460 started by @bashandbone
Summary by Sourcery
Guard TypeScript dependency path normalization against escaping project roots via parent-directory components and perform minor code cleanups and documentation updates.
Bug Fixes:
ParentDircomponents from popping root or prefix path segments.Enhancements:
Documentation:
.jules/sentinel.md.