Repository navigation
fix: key unlock leases by native lock identity - #73
Merged
Merged
Conversation
Derive the unlock operation lease from the canonical native lock directory instead of the caller's --codex-home spelling and environment. The lease file now lives in a codex-unlock-owned directory beside the realpath of thread-writer-locks (normally $CODEX_HOME/codex-unlock) and is keyed by the lock directory's device/inode and the thread UUID. Symlinked homes, homes whose thread-writer-locks is a symlink to the same target, and case-variant spellings now contend on one lease, and shells with different TMPDIR or XDG_RUNTIME_DIR values are serialized. There is no shared predictable temporary root left for another user to pre-create. The parent must be owned by the current user, the lease directory must be a private non-symlink directory, the lease file a private regular single-link file, and the path must still name the locked inode after flock; any failure refuses without signaling. Leases taken by 0.4.0 and earlier are not seen by this version; the safety race matrix documents that upgrade limitation. Closes #53 Closes #60 Closes #64
abruption
force-pushed
the
fix/unlock-lease-identity
branch
from
September 29, 2026 00:04
1527bb5 to
1bd2f39
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Derive the unlock operation lease from the native lock it protects instead of from the caller's
--codex-homespelling and environment.sha256("codex-unlock-lease-v2" \0 dev \0 ino \0 threadId), where dev/ino come fromrealpathSync.native(<home>/thread-writer-locks). Symlinked homes, homes whosethread-writer-locksis a symlink to the same target (security: case-variant --codex-home paths bypass unlock serialization and send duplicate SIGTERM #53 comment), and case-variant spellings (security: case-variant --codex-home paths bypass unlock serialization and send duplicate SIGTERM #53) now contend on one lease.$CODEX_HOME/codex-unlock/<key>.lock.TMPDIR,XDG_RUNTIME_DIR, andHOMEare no longer read (fix: environment-dependent coordination root lets concurrent unlocks bypass serialization #64), and there is no shared predictable/tmproot another user can pre-create (fix: predictable shared tmp coordination fallback allows unlock denial on Linux #60). Nothing is created insidethread-writer-locks, and native lock files are never touched.O_CREAT | O_NOFOLLOWand must be a same-user, private, single-link regular file; afterflock, the directory inode must be unchanged and still private, and the path must still name the locked inode (coordination_path_changed). Any failure refuses without signaling.runtimeDirectoryparameter was removed.Closes #53
Closes #60
Closes #64
Type
Safety impact
Changes unlock coordination only; lock probing, owner validation, and signaling are unchanged. New coordination reasons (
lock_directory_unavailable,coordination_parent_unavailable,coordination_parent_is_not_owned,coordination_path_changed) are reported inside the existingunlock_coordination_failed:<reason>form, andruntime_directory_is_not_privateno longer occurs. The JSON schema is unchanged.Checklist
npm run checkpassesnpm run lintpassesnpm testpasses (91 pass, 0 fail, 0 skipped; the case-variant test ran on a case-insensitive APFS volume)npm run smoke:packagepassesTests
Real advisory locks with fixture owners only:
TMPDIR/XDG_RUNTIME_DIRsend exactly oneSIGTERM;codex-unlock-<uid>underTMPDIRno longer denies unlock;codex-unlock/(0755 directory, symlinked directory, regular file) and a symlinked lease file are refused;The three new CLI tests fail when
src/coordination.tsis reverted tomain.Notes (maintainer decisions)
codex-unlock/directory in the Codex home (besidethread-writer-locks) instead of a runtime/temporary directory. A per-user home location was considered, but it would require an environment override for tests, which reintroduces fix: environment-dependent coordination root lets concurrent unlocks bypass serialization #64. The Codex home shares the native lock's trust boundary.thread-writer-locksproduces the same key under different lease directories. If the canonical parent of the lock directory is owned by another user, unlock now refuses.~/.codexcan legitimately be 0775, and an attacker with that access could already replacethread-writer-locksandsessions. The post-flockrevalidation covers path replacement.