Skip to content

fix(quarantine): reject path-traversal in restore target - #1

Merged
ruaavell merged 1 commit into
mainfrom
fix/quarantine-restore-path-traversal
Oct 17, 2026
Merged

ruaavell merged 1 commit into
mainfrom
fix/quarantine-restore-path-traversal

Conversation

@ruaavell

Copy link
Copy Markdown
Owner

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.

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>
@ruaavell
ruaavell merged commit f33b83d into main Oct 17, 2026
1 of 2 checks passed
@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Reject traversal paths when restoring quarantined files

🐞 Bug fix 🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Reject restore targets containing .. while retaining the existing bare-filename guard.
• Add forged-index tests confirming traversal is rejected without moving the quarantined file.
Diagram

graph TD
  IDX["JSONL index"] --> REST["Restore request"] --> SRC["Quarantined file"] --> GUARD{"Safe path?"} -->|Yes| DST["Restore target"]
  GUARD -->|No| ERR["Reject restore"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Authenticate quarantine index entries
  • ➕ Prevents tampered entries from substituting arbitrary restore paths, including absolute paths.
  • ➖ Requires integrity-key management and an index migration strategy.
2. Constrain restores to a trusted directory
  • ➕ Provides an explicit destination boundary independent of index contents.
  • ➖ Changes the behavior of restoring files to their original absolute paths.

Recommendation: The component check is a small, appropriate defense against .. traversal. It does not fully address the stated attacker-tamperable-index threat: a forged entry can still name an arbitrary absolute path. If preventing arbitrary destinations is the goal, authenticate the recorded path or establish a trusted restore boundary.

Files changed (1) +65 / -5

Bug fix (1) +65 / -5
quarantine.rsReject traversal components in quarantine restore paths +65/-5

Reject traversal components in quarantine restore paths

• Restore now rejects an indexed original path containing a parent-directory component, alongside the existing bare-filename check, and reports the unsafe path in the error. Two tests forge traversal paths in the JSONL index and verify that restore fails while the quarantined file remains in place.

src/quarantine.rs

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Parent-relative files cannot be restored 🐞 Bug ≡ Correctness
Description
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.
Code

src/quarantine.rs[R210-213]

+    if e.original_path
+            .components()
+            .any(|c| c == std::path::Component::ParentDir)
+        || e.original_path.components().count() < 2
Evidence
The CLI passes user-supplied paths directly to quarantine_add, which records the source path
unchanged. The new guard rejects that recorded path if it contains .., before the restore rename
occurs.

src/main.rs[274-280]
src/quarantine.rs[80-86]
src/quarantine.rs[210-226]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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

Dismiss ↗ | View ↗


Grey Divider

Context sources
Review mode: Auto: ⚖️ Balanced: Security-sensitive restore-path validation warrants a complete careful review.

Grey Divider

Tip of the day
💡 Did you know, you can see how risky a PR is at a glance with blast radius labels

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread src/quarantine.rs
Comment on lines +210 to +213
if e.original_path
.components()
.any(|c| c == std::path::Component::ParentDir)
|| e.original_path.components().count() < 2

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

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

Dismiss ↗ | View ↗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants