fix(cli): confine attachment downloads to --dir, sanitize mail filename (P1 path traversal)#113
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
Next review available in: 30 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…ename attachment.filename is mail-controlled. Path::join with an absolute or ../-laden name escaped the user's --dir, letting a sender overwrite arbitrary user-writable files. Reduce the name to its final path component (with a stable per-attachment fallback) before joining so the copy stays a direct child of the chosen directory.
8eb00c0 to
94a8377
Compare
Problem (P1 security — arbitrary file write)
mxr attachments download <id> --dir <dir>didtarget_dir.join(&attachment.filename)with the raw, mail-controlled filename.Path::joindiscards the base on an absolute component and../walks upward, so a hostile filename (/etc/crontab,../../../.ssh/authorized_keys) writes outside--dir— arbitrary-file-overwrite / code-exec. The daemon side already sanitizes; this CLI convenience copy did not.Fix
New
safe_download_namereduces the filename to its final path component (Path::file_name()), falling back to a stableattachment-<id>for.././empty/non-UTF-8.target_dir.join(name)is then always a direct child. Normal filenames unchanged. Tests cover../../evil,/etc/evil,.., `` (all confined) andreport.pdf(preserved).CI note: workspace clippy is red on pre-existing 1.97 lints until #111 (CI-unblock) merges; will rebase.
Summary by cubic
Sanitizes attachment filenames and confines downloads to the chosen
--dir, preventing path traversal and arbitrary file writes. Normal filenames remain unchanged.safe_download_nameto keep only the final path component; falls back toattachment-<id>for..,., empty, or non-UTF-8 names.--dirdownloads now always write directly under the chosen directory; tests cover../../evil,/etc/evil,.., empty, andreport.pdf.Written for commit 94a8377. Summary will update on new commits.