Skip to content

fix: predictable shared tmp coordination fallback allows unlock denial on Linux #60

Closed

Description

@abruption

What happened

On Linux without XDG_RUNTIME_DIR, the unlock coordination directory falls back to $TMPDIR or /tmp with a predictable name, codex-unlock-<uid>. Another local user can create that path first (as a directory they own or a symlink). The privacy check then fails, and every unlock by the victim is refused with coordination_directory_is_not_private.

Symlink and ownership attacks are correctly rejected (lstat, owner, mode, O_NOFOLLOW, and nlink checks), so the remaining impact is denial of service only.

Also, chmodSync(root, 0o700) runs only after privateDirectory has already confirmed that no group/other bits are set, so it has no effect.

What you expected

The fallback location cannot be pre-empted by other users; for example it lives under a user-owned directory such as $XDG_STATE_HOME or ~/.cache, or the refusal reason clearly identifies a foreign-owned coordination directory.

Environment

  • codex-unlock 0.4.0 at 6227e6c
  • Linux with a shared /tmp and no XDG_RUNTIME_DIR (for example non-login SSH sessions, cron, containers). macOS uses a per-user TMPDIR and is not affected.

Source evidence

  • Predictable shared fallback:
    function runtimeRoot(uid: number, override?: string): string {
    const configured = override ?? process.env.XDG_RUNTIME_DIR;
    if (configured !== undefined) {
    if (!isAbsolute(configured) || !privateDirectory(configured, uid)) {
    throw new Error("runtime_directory_is_not_private");
    }
    return join(configured, "codex-unlock");
    }
    return join(tmpdir(), `codex-unlock-${uid}`);
    }
  • Refusal when the directory is not private:
    root = runtimeRoot(uid, runtimeDirectory);
    mkdirSync(root, { mode: 0o700, recursive: true });
    if (!privateDirectory(root, uid)) {
    return { status: "unknown", reason: "coordination_directory_is_not_private" };
    }
    chmodSync(root, 0o700);

Acceptance criteria

  • The fallback directory is in a user-owned location, or the limitation is documented.
  • A foreign-owned pre-existing directory yields a specific, actionable reason.
  • A test covers a pre-existing foreign-owned or symlinked fallback path.

Scope and limitations

  • Availability impact only; no signal is sent to a wrong process, and no data is read or written through the attacker's path.
  • Analysed from source and fixtures; a multi-user reproduction was not performed.

Checked

Activity

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

    @abruption
    OwnerAuthor

    The same fallback is also reached on macOS: when TMPDIR is unset (cron, some SSH sessions, sudo -u), os.tmpdir() returns /tmp and the lease root becomes /tmp/codex-unlock-<uid>. The pre-creation denial described here is therefore not Linux-only.

    Source:

    function runtimeRoot(uid: number, override?: string): string {
    const configured = override ?? process.env.XDG_RUNTIME_DIR;
    if (configured !== undefined) {
    if (!isAbsolute(configured) || !privateDirectory(configured, uid)) {
    throw new Error("runtime_directory_is_not_private");
    }
    return join(configured, "codex-unlock");
    }
    return join(tmpdir(), `codex-unlock-${uid}`);
    }

  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