Repository navigation
Description
What happened
Human-readable output of list, inspect, and unlock prints several externally derived strings verbatim, including C0/C1 control characters and escape sequences. printable() only substitutes empty values.
Affected fields include:
owner.arguments(fromps -o args=) — includes the Codex prompt when passed on the command lineowner.cwd(fromlsof//proc/<pid>/cwd)transcript.lastRecord.eventType(the rawpayload.typestring from the rollout JSONL)- lock and transcript paths, and error text included in
reasons/ stderr
Reproduced with a same-user fixture owner whose cwd was evil\e]0;PWNED\a\e[31mRED, whose argv contained \e[2J\e[HSafe to unlock: yes\e]52;c;<base64>\a, and whose rollout's last record had payload.type = "task_complete\u001b[2K\rSafe to unlock: yes". inspect output (through cat -v):
Owner command: ...^[[2J^[[HSafe to unlock: yes^[]52;c;ZWNobyBoaQ==^G
Owner cwd: .../evil^[]0;PWNED^G^[[31mRED
Last event: task_complete^[[2K^MSafe to unlock: yes
On a terminal this can clear the screen, forge a Safe to unlock: yes line, set the window title, write the clipboard via OSC 52, or render OSC 8 links. The list table prints the same values.
What you expected
A safety diagnostic's human output cannot be visually spoofed by prompt text, directory names, or transcript content. Control characters are rendered visibly (for example \x1b, \n) before printing. --json output is already safe because JSON.stringify escapes them.
Environment
codex-unlock0.4.0 at6227e6c- macOS 27.0 arm64 (BSD
psandlsofboth pass the bytes through unescaped), Node.js 22.14.0
Source evidence
printable()does not sanitize:Lines 164 to 166 in 6227e6c
function printable(value: string | number | null): string { return value === null || value === "" ? "-" : String(value); } inspectoutput:Lines 168 to 195 in 6227e6c
function printInspection(result: InspectionResult): void { console.log(`Thread: ${result.threadId}`); console.log(`Classification: ${result.classification}`); console.log(`Lock probe: ${result.lock.probe.status}`); console.log(`Lock path: ${result.lock.path}`); if (result.owner) { console.log(`Owner PID: ${result.owner.pid}`); console.log(`Owner command: ${printable(result.owner.arguments)}`); console.log(`Owner start: ${printable(result.owner.startTime)}`); console.log(`Owner PPID: ${printable(result.owner.ppid)}`); console.log(`Owner TTY: ${printable(result.owner.tty)}`); console.log(`Owner cwd: ${printable(result.owner.cwd)}`); } else { console.log("Owner: -"); } console.log(`Transcript: ${printable(result.transcript.path)}`); console.log( `Last event: ${printable(result.transcript.lastRecord?.eventType ?? null)}`, ); console.log(`Stable: ${result.transcript.stable === true ? "yes" : "no"}`); console.log(`Safe to unlock: ${result.safeToUnlock ? "yes" : "no"}`); if (result.blockers.length > 0) { console.log(`Blockers: ${result.blockers.join(", ")}`); } if (result.warnings.length > 0) { console.log(`Warnings: ${result.warnings.join(", ")}`); } } listLAST EVENT column:Lines 197 to 219 in 6227e6c
function printList(result: ListResult): void { if (result.sessions.length === 0) { console.log(`No Codex thread lock files found under ${result.codexHome}.`); return; } const headers = ["THREAD", "CLASSIFICATION", "PROBE", "PID", "LAST EVENT", "STABLE", "SAFE"]; const rows = result.sessions.map((session) => [ session.threadId, session.classification, session.lock.probe.status, printable(session.owner?.pid ?? null), printable(session.transcript.lastRecord?.eventType ?? null), session.transcript.stable === true ? "yes" : "no", session.safeToUnlock ? "yes" : "no", ]); const widths = headers.map((header, index) => Math.max(header.length, ...rows.map((row) => row[index].length)), ); console.log(headers.map((header, index) => header.padEnd(widths[index])).join(" ")); for (const row of rows) { console.log(row.map((value, index) => value.padEnd(widths[index])).join(" ")); } } unlockreasons:Lines 221 to 233 in 6227e6c
function printUnlock(result: UnlockResult): void { console.log(`Thread: ${result.threadId}`); console.log(`Outcome: ${result.outcome}`); console.log(`PID: ${printable(result.pid)}`); console.log(`Signal: ${printable(result.signalSent)}`); console.log(`Process exited: ${printable(result.processExited === null ? null : result.processExited ? "yes" : "no")}`); console.log(`Lock released: ${result.lockReleased ? "yes" : "no"}`); console.log(`Transcript unchanged: ${printable(result.transcriptUnchanged === null ? null : result.transcriptUnchanged ? "yes" : "no")}`); console.log("Lock file removed by codex-unlock: no"); if (result.reasons.length > 0) { console.log(`Reasons: ${result.reasons.join(", ")}`); } } - Error text on stderr:
Lines 399 to 401 in 6227e6c
} else { console.error(`codex-unlock: ${errorText(error)}`); } eventTypetaken verbatim from transcript:codex-unlock/src/transcript.ts
Line 103 in 6227e6c
eventType: payload && typeof payload.type === "string" ? payload.type : null,
Acceptance criteria
- All externally derived strings in human output (arguments, cwd, TTY, lock/transcript paths, event type, reasons, stderr error text) have C0, DEL, and C1 control characters (including ESC) replaced with a visible escape form.
- Tests cover
inspect,list, andunlockwith control characters in argv, cwd, and event type and assert that no raw\x1b,\r, or\nfrom those fields reaches stdout/stderr. --jsonoutput is unchanged.
Scope and limitations
- Requires the attacker to influence the owner's argv, working directory name, or transcript content (for example a pasted prompt or an untrusted extracted directory). It does not change the actual safety decision or cause a signal by itself; the risk is misleading the operator.
- Reproduced with fixture processes only.
Checked
- No existing issue covers output sanitization.
Activity
fix: escape terminal controls and bound transcript ordinals