Skip to content

fix(runtime): reject hard-linked private snapshot files - #9560

Open
Duang777 wants to merge 1 commit into
mainfrom
cursor/reject-hardlinked-private-snapshots-b3cb
Open

Duang777 wants to merge 1 commit into
mainfrom
cursor/reject-hardlinked-private-snapshots-b3cb

Conversation

@Duang777

Copy link
Copy Markdown
Collaborator

Goal And Delivered Outcome

Private Effect snapshot and response-sink admission treated a hard link as an ordinary private file. Symlink checks do not cover that alias: lstat reports a hard link as a regular file, O_NOFOLLOW does not refuse it, and the same uid/mode/inode checks still pass. A pre-existing sink path inside loopx-effect-* that is a hard link to a same-uid file outside that directory was admitted. writePrivateResponse then truncated that external inode.

  • Outcome basis / optional anchor: self-discovered defect on current main. No tracker issue.
  • Goal/source and gap: private snapshot leaves must be exclusive regular files, the same alias class already closed for quota and checkpoint artifacts. Snapshot admission stopped at symlink, owner, and mode.
  • Observable before → after, with the validation row that proves it: on unfixed main, readPrivateJsonSnapshot returned the hard-linked JSON, and openPrivateResponseSink + writePrivateResponse replaced the external sentinel with {"clobber":true}. require_private_path and _read_local_snapshot_response also accepted the link. After this change those calls fail closed, and the sentinel bytes stay unchanged.
  • Issue/task and intended base: no issue. Base is main at 811c1a1f66652d3fc3b9830d467e14b45b7423c1.

Author Declaration

Implemented against

  • Specification and revision: no written specification; the request in this PR is the basis.
  • Criteria:
Criterion (spec clause) Disposition Symbol / path Test or command
Admit a private snapshot/sink leaf only when it is an exclusive regular file (isFile() and nlink === 1; opened fd still nlink === 1) implemented privateFile in loopx/control_plane/effect_runtime_snapshot.ts node --no-warnings --experimental-sqlite --experimental-strip-types --test tests/control_plane_ts/effect_runtime_snapshot.test.ts
Admit a non-directory private leaf only when S_ISREG and st_nlink == 1, including the opened fd; directories keep ordinary directory link counts implemented require_private_path in loopx/control_plane/runtime/private_permissions.py uv run --extra test python -m pytest tests/control_plane/test_private_snapshot_exclusive_file.py -q
Hard-linked paths fail closed with the existing public errors and the external file is not written, truncated, or repaired implemented TS wrappers and Python OSError same two commands; sentinel bytes asserted
Platforms that cannot create hard links skip those cases implemented both new tests skip on EPERM / ENOTSUP / EOPNOTSUPP / EXDEV / ENOSYS
  • Self-check before submission: reproduced the read acceptance and the sink clobber on unfixed main, then re-ran the same tests after the admission change. Also ran the existing snapshot integration cases, the Windows privacy file (skipped on this host), scoped ruff, and npm run typecheck:control-plane. Did not audit unrelated hard-link sites.

Scope And Continuation

  • Completed scope and remaining work: snapshot/sink admission now requires an exclusive regular file on both the TypeScript and Python private-path checks. Other trees (checkpoint capture, history, leases) are outside this change.
  • Slice boundary / successor: complete within this scope. A hard link created after the handle is returned and before truncate is still a narrow time-of-check window; this PR closes the pre-existing alias that admission used to accept.

Validation

  • Tested revision: 02dcffae4ca9e22f48b3ca3010bcf50dc9e909a1
  • Run state: finished
  • Input classes: synthetic
Check kind Result Public-safe evidence / limitation
regression_parity failed Pre-fix, same new tests, production unchanged. node --no-warnings --experimental-sqlite --experimental-strip-types --test tests/control_plane_ts/effect_runtime_snapshot.test.ts: 4 tests, 2 pass, 2 fail. The read test received the hard-linked object. The sink test replaced the external sentinel with {"clobber":true}. uv run --extra test python -m pytest tests/control_plane/test_private_snapshot_exclusive_file.py -q: 2 failed, 2 passed. require_private_path did not raise; _read_local_snapshot_response did not raise EffectRuntimeResponseAmbiguous.
unit passed Post-fix. Same node command: 4 tests, 4 pass, 0 fail. Same pytest command: 4 passed.
unit passed uv run --extra test python -m pytest tests/control_plane/test_windows_snapshot_privacy.py -q: 18 skipped on this non-Windows host.
integration passed uv run --extra test python -m pytest tests/control_plane/test_effect_runtime_integration.py::test_large_local_response_digest_failure_is_ambiguous tests/control_plane/test_effect_runtime_integration.py::test_controller_snapshot_retains_private_file_and_method_guards -q: 2 passed.
static passed uv run --extra test python -m ruff check loopx/control_plane/runtime/private_permissions.py tests/control_plane/test_private_snapshot_exclusive_file.py: all checks passed. npm run typecheck:control-plane: exit 0. scripts/check_rfc_bilingual.py --base origin/main --staged: passed (no paired RFC).
  • Coverage and gaps: the new cases cover the hard-linked reader, the hard-linked sink write, Python leaf admission with and without an open descriptor, snapshot readback, an exclusive file, and a directory whose link count is not 1. Windows DACL behavior was not executed here. The post-admission race noted above is untested.

See validation disclosure guidance.

Frontend / Visual Evidence

  • UI impact: none
  • Before: N/A
  • After: N/A
  • First viewport and preview: N/A
  • States and viewports shown: N/A
  • Source data: none
  • Attention review: N/A
  • Craft review: N/A

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Refactoring (no functional changes)
  • Documentation update
  • Test update

LoopX Area

  • Control plane (goals, todos, quota, scheduler, registry, runtime)
  • Benchmark boundary (adapters, runners, verifiers, scoring, evidence)
  • Capability or extension (providers, adapters, skills)
  • Public docs or presentation surface (README, protocols, dashboard)
  • Build, packaging, installer, or CI
  • Host or runtime integration

Technical Direction

  • Direction / acceptance reference, when applicable: core control-plane hardening. Private snapshot IO only; no shared-authority RFC fixture change.

Shared-authority RFC fixture impact

N/A

Boundary Checklist

  • Neither the diff nor this PR body/comments/attachments disclose private state, credentials, raw traces or verifier output, internal links, or local machine paths (including .loopx/, .codex/goals/, and live ACTIVE_GOAL_STATE.md).
  • I did not duplicate maintainer-owned benchmark work unless a maintainer split out a public issue for it.
  • I kept the change scoped to the linked issue/task.
  • Existing English/Chinese RFC pairs (including ledger entries) both have a diff, and the local premerge check python3 scripts/check_rfc_bilingual.py --base origin/main --head HEAD passes, or no paired RFC changed.
  • I completed the visual evidence section for UI changes, or marked UI impact none.
  • Every commit includes a DCO Signed-off-by trailer (git commit -s).
Open in Web Open in Cursor 

Private effect snapshot admission rejected symlinks but still treated a
hard link as an exclusive regular file. A same-uid hard link from a
loopx-effect-* sink to a file outside that directory was readable and
writable, so the response write truncated the external inode.

Admit a private snapshot leaf only when it is an exclusive regular file
(nlink === 1 / st_nlink == 1). Directories keep their ordinary link count.
A hard-linked leaf fails closed and is not truncated or repaired.

Signed-off-by: Duang777 <[email protected]>

This branch has not been deployed

No deployments
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.

1 participant