Repository navigation
fix(quarantine): reject path-traversal in restore target - #1
Conversation
The quarantine index (JSONL) is untrusted and attacker-tamperable. A forged entry with original_path containing '..' traversal components or a bare filename could make quarantine_restore write the quarantined file to an arbitrary location. Reject any original_path with a ParentDir component or fewer than 2 components (bare filename). Legitimate absolute paths (e.g. Windows C:\Users\...\file.txt) are still restored correctly. Add restore_rejects_traversal_path and restore_rejects_traversal_relative integration tests. Co-Authored-By: Claude Code <noreply@anthropic.com>
PR Summary by QodoReject traversal paths when restoring quarantined files
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
Code Review by Qodo
1. Parent-relative files cannot be restored
|
| if e.original_path | ||
| .components() | ||
| .any(|c| c == std::path::Component::ParentDir) | ||
| || e.original_path.components().count() < 2 |
There was a problem hiding this comment.
1. Parent-relative files cannot be restored 🐞 Bug ≡ Correctness
restore_in rejects every ParentDir component, including one in a path that quarantine_add recorded from a legitimate source. When a user adds an existing file as ../dir/file.bin, the add succeeds, but restoring its ID returns an error and leaves the file in quarantine.
Agent Prompt
## Issue description
Legitimate files added through paths containing `..` cannot be restored because add records the path unchanged while restore rejects it.
## Fix Focus Areas
- src/quarantine.rs[80-86]
- src/quarantine.rs[210-213]
## Recommended Fix
Resolve legitimate source paths to safe, absolute paths when adding files, and store the resolved path as `original_path`. Keep forged traversal paths rejected during restore; account for previously recorded legitimate paths containing `..` without treating arbitrary tampered entries as trusted.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
The quarantine index (JSONL) is untrusted and attacker-tamperable. A forged entry with original_path containing '..' traversal components or a bare filename could make quarantine_restore write the quarantined file to an arbitrary location.
Reject any original_path with a ParentDir component or fewer than 2 components (bare filename). Legitimate absolute paths (e.g. Windows C:\Users...\file.txt) are still restored correctly.
Add restore_rejects_traversal_path and
restore_rejects_traversal_relative integration tests.