Skip to content

fix: escape terminal controls and bound transcript ordinals - #76

Merged
abruption merged 1 commit into
mainfrom
fix/output-integrity
Sep 29, 2026
Merged

abruption merged 1 commit into
mainfrom
fix/output-integrity

Conversation

@abruption

Copy link
Copy Markdown
Owner

Stacked on #72 and #75. Review only the last commit (fix: escape terminal controls and bound transcript ordinals). Merge #72 and #75 first.

Summary

#54 (terminal control sequences in human output, src/cli.ts)

  • A new terminalSafe() renders C0, DEL, C1 (including ESC) and Unicode bidi/line-separator controls (U+061C, U+200E/F, U+2028/9, U+202A–E, U+2066–9) visibly as \n, \r, \t, \xHH, or \uHHHH.
  • It is applied to every externally sourced value in human-readable output: owner arguments, cwd, TTY, start time, lock and transcript paths, the LAST EVENT column and empty-list Codex home in list, blockers/warnings/reasons, the three stderr error paths, and the check-update cache warning. list column widths use the escaped length.
  • JSON output is unchanged byte for byte; JSON escaping already makes it safe.

#56 (non-integer transcript ordinals, src/transcript.ts)

  • ordinal is emitted only when Number.isSafeInteger(value) && value >= 0; otherwise it is null. The schema is not widened.

Closes #54
Closes #56

Type

  • fix

Safety impact

No change to lock probing, owner validation, signaling, or safety decisions. Human output can no longer be used to forge lines (for example a fake Safe to unlock: yes) or send terminal control sequences. JSON schema and types are unchanged; ordinal values that violated the schema are now null.

Checklist

  • npm run check passes
  • npm run lint passes
  • npm test passes (118 pass, 0 fail)
  • npm run smoke:package passes
  • Commits follow Conventional Commits
  • Documentation is updated when behavior or output changed
  • No tokens, private paths, or unredacted process data are in the diff

Tests

  • Owner fixtures with a control-character cwd, a retitled argv (OSC 52, screen clear, forged lines), and a control-character transcript event type: inspect, list, and unlock human output contain no raw C0/C1/\r, no forged line starting with Safe to unlock: yes, exactly two list lines, and the escaped forms.
  • stderr error path with a control-character missing home.
  • Ordinals 3, 1.5, -1, 2^53, 1e308, and "4": inspect, list, and unlock JSON validate against the schema with ajv.
  • The three new tests fail when the source changes are reverted.

Notes

  • Backslashes are not escaped, so normal paths display unchanged. As a result, a value that literally contains the text \x1b is indistinguishable from an escaped ESC in human output. Line forgery and terminal control are still prevented.
  • Visually confusable (homoglyph) characters are out of scope.
  • macOS ps/lsof already render control characters in argv and cwd as ^[, so the raw-byte path for those two fields is exercised on the Linux CI runners; transcript and stderr paths are raw on both platforms.
  • The one no-control-regex lint suppression is scoped to the intended pattern with a justification comment.

@abruption abruption added this to the v0.4.1 milestone Sep 28, 2026
Render externally derived text in human output (owner arguments, cwd,
TTY, lock and transcript paths, event types, blockers, warnings,
reasons, and stderr error text) with visible escapes for C0, DEL, C1,
and Unicode bidirectional or line-separator controls. Prompt text,
directory names, or transcript content can no longer move the cursor,
drive terminal features, or forge result lines. JSON output keeps the
original values under standard JSON escaping.

Emit transcript ordinals only when they are non-negative safe integers
and null otherwise, so inspect, list, and unlock JSON always satisfy
the v1 schema.

Closes #54
Closes #56
@abruption
abruption merged commit 938a65a into main Sep 29, 2026
24 checks passed
@abruption
abruption deleted the fix/output-integrity branch September 29, 2026 00:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: JSON output can violate the v1 schema for non-integer transcript ordinals security: sanitize terminal control sequences in human-readable output

1 participant