Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 2024-05-15 - Path Traversal in Manual Path Component Normalization
**Vulnerability:** Path traversal risk during manual path normalization (when `std::fs::canonicalize` fails). In `typescript.rs`, handling `Component::ParentDir` by only calling `components.pop()` allows excessive `../` to resolve up to the root, bypassing intended base path constraints.
**Learning:** `std::path::Component::ParentDir` shouldn't blindly pop the last component. If the component stack is empty or its last element is also `ParentDir`, popping ignores the traversal intent.
**Prevention:** Explicitly match against the last element of the component stack before handling `ParentDir`. If it's a `RootDir` or `Prefix`, ignore. If it's a `ParentDir` or `None`, push the `ParentDir`. Only pop when the last element is `Normal`.
13 changes: 12 additions & 1 deletion crates/flow/src/incremental/extractors/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,18 @@ impl TypeScriptDependencyExtractor {
for component in resolved.components() {
match component {
std::path::Component::ParentDir => {
components.pop();
let last = components.last().copied();
match last {
Some(std::path::Component::RootDir)
| Some(std::path::Component::Prefix(_)) => {}
Some(std::path::Component::ParentDir) | None => {
components.push(component)
}
Comment on lines +815 to +817
Comment on lines +813 to +817
Some(std::path::Component::Normal(_)) => {
components.pop();
}
Some(std::path::Component::CurDir) => unreachable!(),
}
}
std::path::Component::CurDir => {}
_ => components.push(component),
Expand Down