Skip to content

security: inherited COLUMNS truncates ps args and hides shared app-server owners on Linux #52

Closed

Description

@abruption

What happened

On Linux, unlock can classify a shared codex app-server owner as a non-shared, signalable Codex process when the invoking shell exports COLUMNS.

runCommand passes the full parent environment to diagnostic commands, overriding only LC_ALL and LANG. Owner arguments are read with ps -p <pid> -o args= without -ww. procps-ng honours COLUMNS even when stdout is a pipe and truncates the args column to that width. The shared-service regex is then evaluated against the truncated string, so an app-server, remote-control, or daemon token beyond column COLUMNS is silently lost while identityComplete remains true.

Because revalidation samples args the same way, the truncated value is also stable across the before/after comparison, so revalidation does not catch it either.

Reproduced with procps-ng 4.0.4 (Ubuntu 24.04, aarch64), using a same-user dummy process renamed to a long path:

$ ps -p $PID -o args= | cat
/very/long/path/aaaa…aaaa/codex app-server --x
$ COLUMNS=80 ps -p $PID -o args= | cat
/very/long/path/aaaa…aaaa

A real-world trigger is an editor-bundled Codex binary (for example under ~/.vscode*/extensions/openai.chatgpt-*/bin/...) whose absolute path alone is close to or longer than 80 columns, run from a shell that exports COLUMNS.

macOS ps did not truncate piped output in the same test.

What you expected

A shared app-server owner is refused with lock_owner_is_shared_service regardless of the caller's terminal width variables, as required by the repository safety invariants ("Refuse shared app-server, Remote Control, daemon, ambiguous, or changing owners"). If the full argument vector cannot be obtained, the owner identity should be unknown.

Environment

  • codex-unlock 0.4.0 at 6227e6c
  • Ubuntu 24.04.5 LTS aarch64, procps-ng 4.0.4 (affected)
  • macOS 27.0 arm64 (not reproduced)

Source evidence

  • Environment is inherited by diagnostic commands:

    codex-unlock/src/util.ts

    Lines 47 to 51 in 6227e6c

    const isolatedProcessGroup = process.platform !== "win32";
    const child = spawn(executable, args, {
    detached: isolatedProcessGroup,
    env: { ...process.env, LC_ALL: "C", LANG: "C" },
    stdio: ["ignore", "pipe", "pipe"],
  • ps -o <field>= without -ww:

    codex-unlock/src/process.ts

    Lines 102 to 103 in 6227e6c

    async function psField(pid: number, field: string): Promise<ProcessFieldObservation> {
    const result = await runCommand("ps", ["-p", String(pid), "-o", `${field}=`]);
  • args sampled via that helper:
    psField(candidate.pid, "args"),
  • Shared-service classification on the possibly truncated value:
    const isSharedService = /\b(?:app-server|remote-control|daemon)\b/i.test(args ?? "");

Acceptance criteria

  • Diagnostic commands do not inherit COLUMNS, LINES, PS_FORMAT, or PS_PERSONALITY (or run with an explicit minimal environment).
  • Owner arguments are read without width truncation (for example ps -ww, or /proc/<pid>/cmdline on Linux).
  • A regression test sets COLUMNS=40 and still yields lock_owner_is_shared_service for an owner whose app-server token appears after column 40.
  • Width-limited or otherwise incomplete argument evidence fails closed as unknown.

Scope and limitations

  • Not exploitable by another user: it depends on the invoking user's own environment and on the owner being a same-user process that otherwise passes every unlock gate (single lock, stable transcript ending in task_complete).
  • Reproduced with ps on a dummy process; no real Codex app-server was signaled.
  • Related hardening, not a separate finding: there is no final start-time/lock re-check immediately before process.kill, after the full transcript hash in revalidation (

    codex-unlock/src/unlock.ts

    Lines 269 to 300 in 6227e6c

    if (finalInspection.transcript.path && beforeHash !== null) {
    try {
    const finalHash = await stableFileHash(finalInspection.transcript.path);
    if (
    finalHash.hash !== beforeHash ||
    !sameSnapshot(finalHash.snapshot, finalInspection.transcript.snapshot)
    ) {
    revalidationReasons.push("transcript_changed_during_revalidation");
    }
    } catch (error) {
    revalidationReasons.push(`transcript_revalidation_hash_failed:${errorText(error)}`);
    }
    }
    if (revalidationReasons.length > 0) {
    return unlockResult(inspection, {
    outcome: "refused",
    changed: false,
    pid: owner.pid,
    signalSent: null,
    processExited: null,
    processObservation: null,
    lockReleased: false,
    transcriptUnchanged: null,
    reasons: unique(revalidationReasons),
    });
    }
    return await terminateRevalidatedOwner(
    {
    inspection,
    owner: { ...owner, startTime: owner.startTime! },
    transcriptPath,
    transcriptHash: beforeHash!,
    ,
    async function terminateRevalidatedOwner(
    evidence: RevalidatedUnlockEvidence,
    options: DoctorOptions,
    ): Promise<UnlockResult> {
    const { inspection, owner, transcriptPath, transcriptHash } = evidence;
    try {
    process.kill(owner.pid, "SIGTERM");
    ). Checking start time immediately before signaling would further shrink the PID-reuse window.

Checked

Activity

  1. added
    bug
    on Sep 28, 2026
  2. added this to the v0.4.1 milestone on Sep 28, 2026
  3. added a commit that references this issue on Sep 29, 2026
    8b878bc
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