fix(export): exclude symlinks from the build export archive (Closes #104) - #166
Conversation
|
Warning Review limit reached
Next review available in: 2 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: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
4c403cd
into
harsharajkumar-273:main
Closes #104
What the issue predicts, and what actually happens
The issue expects
archiverto follow symlinks and pull host file contents into the zip. I installedarchiver@7.0.1— the version pinned inbackend/package.json— and reproducedexportZipexactly, same constructor options and samearchive.directory(outputPath, false)call, against an output directory containing a link to a file outside it and a link to/etc.Archiver 7.0.1 does not dereference symlinks. It stored both as symlink entries (mode
0o120000) and rewrote the absolute targets into relative ones (/etcbecame../../../../etc). The archive contained the link paths, not the contents of the linked files. I don't believe the backend arbitrary-file-read described in the issue is reachable on this version.The real exposure points the other way
Extracting that archive with
unziprecreated both symlinks, still resolving outside the extraction directory — reading through one returned content from outside the extraction root.So the risk isn't the backend host; it's whoever downloads the export. A cloned repository's contents are attacker-controlled and git records symlinks, so a malicious PreTeXt repo can commit links that survive into the exported zip. Anyone extracting it with a standard tool (
unzip,bsdtar, macOS Archive Utility) materialises links pointing outside their extraction directory — the zip symlink traversal pattern (CWE-59), landing on the user rather than the server.Change
archive.directory()now takes an entry filter that drops symlinks:entry.statscomes from anlstat, so this identifies the link itself rather than whatever it points at.Verification
npx tsc --noEmitinbackend/clean.An alternative, if you'd prefer it
This drops symlinks outright. If you'd rather resolve and validate them — keeping links whose targets stay inside
outputPath—resolveContainedPathinbackend/src/utils/pathContainment.tsalready performs exactly that realpath-based containment check, andupdateFileuses it for the same class of problem. Say the word and I'll switch this to reuse it.Note:
npm testis red on cleanmainindependently of this branch.