Skip to content

[WRONG BRANCH] fix(lab): reject symlinked purge directories - #245

Draft
luvs01 wants to merge 1 commit into
mainfrom
codex/fix-vulnerability-in-lab-purge-functionality
Draft

[WRONG BRANCH] fix(lab): reject symlinked purge directories#245
luvs01 wants to merge 1 commit into
mainfrom
codex/fix-vulnerability-in-lab-purge-functionality

Conversation

@luvs01

@luvs01 luvs01 commented Aug 11, 2026

Copy link
Copy Markdown
Owner

Motivation

  • The sensitive-evidence purge code followed scratch/export directory 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 the scratch and export roots as real, restricted directories, leaving the purge operation vulnerable to symlink redirection.

Description

  • Harden ensureRestrictedDir() to lstatSync() the path, reject symbolic links and non-directory targets, and enforce restrictive permissions where supported by the platform.
  • Ensure ensureLabDirs() creates and validates the scratch and export directory roots by calling ensureRestrictedDir() for them as well as the existing roots.
  • Add a fail-closed check in purgeBoundedDirectory() that lstatSync()-validates the directory root and throws a PurgeError with code scratch_export_unsafe_directory when the root is a symlink or not a directory.
  • Add regression tests that verify normal scratch/export purges still remove bounded content and that purging refuses symbolic-link directory roots for both scratch and export to protect outside files from deletion.

Testing

  • Ran bun x tsc --noEmit (bun run typecheck) and it completed successfully.
  • Ran bun run privacy:scan and it completed successfully.
  • Executed a targeted runtime check that invoked ensureLabDirs() against a symlinked lab/scratch and confirmed the function rejects the symlink (automated script returned success).
  • Attempted bun test tests/lab-evidence-ledger.test.ts locally but the run failed due to the installed Bun runtime missing the node:zlib export zstdDecompressSync (runtime mismatch), so full test execution should be verified in CI with the repository's expected Bun version.

Codex Task

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@luvs01, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 50 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1d4138ad-bbb7-4a29-8b29-0f6f034c1014

📥 Commits

Reviewing files that changed from the base of the PR and between 6d881db and 6ae2a43.

📒 Files selected for processing (3)
  • src/lab/ledger/purge.ts
  • src/lab/paths.ts
  • tests/lab-evidence-ledger.test.ts

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Aug 11, 2026
@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown

⏳ DRAFT

  • wrong target branch (main); retarget to dev.

What to do

  • Retarget this PR to dev — all contributions go to dev.

Its title has been prefixed with [WRONG BRANCH].
This pull request was already a draft. Its draft status will be preserved after every issue above is resolved.

@github-actions github-actions Bot changed the title fix(lab): reject symlinked purge directories [WRONG BRANCH] fix(lab): reject symlinked purge directories Aug 11, 2026
@github-actions
github-actions Bot marked this pull request as draft August 11, 2026 00:33

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread src/lab/ledger/purge.ts

function purgeBoundedDirectory(dirPath: string): void {
if (!existsSync(dirPath)) return;
const metadata = lstatSync(dirPath);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

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

Labels

aardvark bug Something isn't working codex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant