Skip to content

security: case-variant --codex-home paths bypass unlock serialization and send duplicate SIGTERM #53

Closed

Description

@abruption

What happened

Two concurrent unlock invocations for the same thread can both send SIGTERM when their --codex-home arguments differ only in letter case on a case-insensitive filesystem (default APFS).

The operation lease key is the SHA-256 of realpathSync(codexHome) and the thread id. Node's JavaScript realpathSync preserves the caller's spelling on case-insensitive volumes, while realpathSync.native returns the on-disk case:

realpathSync('.../casehome')        -> '.../casehome'
realpathSync.native('.../casehome') -> '.../CaseHome'

Both invocations therefore acquire different lease files, both pass revalidation (the native lock, owner, and lock set are identical), and both signal.

Reproduction with a same-user fixture owner that records each SIGTERM and exits 300 ms later:

Second invocation --codex-home Outcomes A / B SIGTERMs received
CaseHome (identical) unlocked (0) / refused: concurrent_unlock_in_progress (2) 1
casehome unlocked (0) / unlocked (0) 2
CASEHOME unlocked (0) / unlocked (0) 2

The same structure is expected for NFC/NFD-different spellings of the same path (not reproduced).

What you expected

As documented in docs/safety-race-matrix.md: "One private advisory operation lease per canonical home/thread" → "Exactly one SIGTERM; competitor refused", independent of how the home path is spelled.

Environment

  • codex-unlock 0.4.0 at 6227e6c
  • macOS 27.0 arm64, APFS (case-insensitive), Node.js 22.14.0

Source evidence

  • Canonical home via JS realpathSync:
    canonicalHome = realpathSync(codexHome);
  • Lease key derived from that string:
    const key = createHash("sha256")
    .update(canonicalHome)
    .update("\0")
    .update(threadId)
    .digest("hex");
    const path = join(root, `${key}.lock`);
  • Invariant being violated:
    | Two CLI unlocks inspect the same safe owner | One private advisory operation lease per canonical home/thread | Exactly one SIGTERM; competitor refused | `concurrent CLI unlock attempts send at most one SIGTERM` |

Acceptance criteria

  • The lease key is derived from filesystem identity (for example dev:ino of the resolved home or of the native thread lock file) rather than from a path string, or at minimum from realpathSync.native.
  • A regression test on a case-insensitive filesystem runs two concurrent unlocks with case-variant homes and observes exactly one SIGTERM and one concurrent_unlock_in_progress refusal.

Scope and limitations

  • Not exploitable by another user; requires the same user to start two unlocks concurrently with differently spelled paths (for example two scripts).
  • The second SIGTERM normally hits the same exiting owner; if it arrives late it produces ESRCH (termination_failed) or, in the worst case, widens a PID-reuse window.
  • Experiments used scratch fixtures only; no real Codex session was signaled.

Checked

Activity

  1. added
    bug
    on Sep 28, 2026
  2. abruption commented on Sep 28, 2026

    @abruption
    OwnerAuthor

    An additional alias path with the same effect: the lease key is sha256(realpath(codexHome) + threadId), so two different homes whose thread-writer-locks (and sessions) directories are symlinks to the same targets get different keys while inspection resolves the same native lock and owner.

    Reproduced with fixtures: while a lease for home A is held, unlock --codex-home A is refused with concurrent_unlock_in_progress, but unlock --codex-home B (B's subdirectories symlinked to A's) returns unlocked and sends SIGTERM.

    Canonicalizing only the home spelling (for example realpathSync.native) would not close this. Keying the lease on the canonical lock directory or the lock file's device/inode would cover both cases.

    Source:

    canonicalHome = realpathSync(codexHome);
    } catch {
    return { status: "unknown", reason: "coordination_directory_unavailable" };
    }
    const key = createHash("sha256")
    .update(canonicalHome)
    .update("\0")
    .update(threadId)
    .digest("hex");
    (key) vs

    codex-unlock/src/process.ts

    Lines 301 to 321 in 6227e6c

    const intendedDirectory = await realpath(dirname(intendedLockPath));
    intendedCanonical = join(intendedDirectory, basename(intendedLockPath));
    } catch (error) {
    return { paths: [], error: `intended lock directory is unresolved: ${errorText(error)}` };
    }
    const paths: string[] = [];
    for (const path of candidates) {
    if (path.endsWith(" (deleted)")) {
    return { paths: [], error: `open lock path was deleted: ${path}` };
    }
    if (!isAbsolute(path)) {
    return { paths: [], error: `lsof returned a relative lock path: ${path}` };
    }
    try {
    const value = await lstat(path);
    if (value.isSymbolicLink() || !value.isFile()) {
    return { paths: [], error: `open lock path is a symlink or non-regular file: ${path}` };
    }
    const canonicalDirectory = await realpath(dirname(path));
    const canonicalPath = join(canonicalDirectory, basename(path));
    paths.push(canonicalPath === intendedCanonical ? intendedLockPath : canonicalPath);
    (owner lookup canonicalizes the lock directory).

  3. added this to the v0.4.1 milestone on Sep 28, 2026
  4. added a commit that references this issue on Sep 29, 2026
    1bd2f39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions