[WRONG BRANCH] fix(lab): reject symlinked purge directories - #245
Conversation
|
Warning Review limit reached
Next review available in: 50 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: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Comment |
|
✅ Deterministic PR hygiene checks passed. |
⏳ DRAFT
What to do
Its title has been prefixed with |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6ae2a43cda
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| function purgeBoundedDirectory(dirPath: string): void { | ||
| if (!existsSync(dirPath)) return; | ||
| const metadata = lstatSync(dirPath); |
There was a problem hiding this comment.
Pin the purge directory before deleting its contents
When another process can modify the Lab directory concurrently, this lstatSync() check is subject to a TOCTOU race: after validation, the real scratch or export directory can be renamed and replaced with a symlink before readdirSync(dirPath), causing the subsequent path-based rmSync() calls to delete children of the symlink target. Open the directory without following links, retain and verify its descriptor/identity, and perform enumeration and deletion relative to that pinned directory (as the artifact secure-fs code does) so replacing the pathname cannot redirect the purge.
Useful? React with 👍 / 👎.
Motivation
scratch/exportdirectory paths and deleted their children even when those roots were symbolic links, enabling out-of-tree deletion under attacker-controlled or misconfigured filesystem conditions.ensureLabDirs()previously did not create or validate thescratchandexportroots as real, restricted directories, leaving the purge operation vulnerable to symlink redirection.Description
ensureRestrictedDir()tolstatSync()the path, reject symbolic links and non-directory targets, and enforce restrictive permissions where supported by the platform.ensureLabDirs()creates and validates thescratchandexportdirectory roots by callingensureRestrictedDir()for them as well as the existing roots.purgeBoundedDirectory()thatlstatSync()-validates the directory root and throws aPurgeErrorwith codescratch_export_unsafe_directorywhen the root is a symlink or not a directory.scratchandexportto protect outside files from deletion.Testing
bun x tsc --noEmit(bun run typecheck) and it completed successfully.bun run privacy:scanand it completed successfully.ensureLabDirs()against a symlinkedlab/scratchand confirmed the function rejects the symlink (automated script returned success).bun test tests/lab-evidence-ledger.test.tslocally but the run failed due to the installed Bun runtime missing thenode:zlibexportzstdDecompressSync(runtime mismatch), so full test execution should be verified in CI with the repository's expected Bun version.Codex Task