Skip to content

[WRONG BRANCH] cli: validate /healthz version before displaying (prevent terminal-injection) - #374

Draft
luvs01 wants to merge 1 commit into
mainfrom
codex/fix-terminal-escape-injection-vulnerability
Draft

[WRONG BRANCH] cli: validate /healthz version before displaying (prevent terminal-injection)#374
luvs01 wants to merge 1 commit into
mainfrom
codex/fix-terminal-escape-injection-vulnerability

Conversation

@luvs01

@luvs01 luvs01 commented Aug 30, 2026

Copy link
Copy Markdown
Owner

Motivation

  • The /healthz version field is attacker-controlled whenever another process can bind the probed port, and unvalidated strings could include newlines or terminal-control sequences (OSC 52) that reach human-facing commands.
  • The updater already treated /healthz.version as untrusted and validated it with a bounded semver test, so the liveness/version-skew path needed the same protection to avoid diagnostic forgery.

Description

  • Add a shared validator isHealthzVersion in src/server/proxy-liveness.ts that accepts semver-like strings up to 64 bytes and rejects anything else.
  • Use isHealthzVersion in proxyIdentityAt so the discovered version is only carried when it matches the bounded semver pattern.
  • Reuse isHealthzVersion in src/update/job.ts (replacing the module-local isVersionLike) so the update restart probe keeps the same shape validation.
  • Add tests in tests/proxy-liveness.test.ts verifying that an adversarial version containing a newline and OSC 52 is rejected and that valid prerelease/build semver is accepted.

Testing

  • Ran the focused tests bun test tests/proxy-liveness.test.ts tests/cli-version-skew.test.ts and they passed (87 tests total).
  • Ran the update-focused tests with the repository Bun binary via ./node_modules/bun/bin/bun.exe test tests/update-job.test.ts and they passed (54 tests).
  • Ran bun run typecheck and bun run privacy:scan (both succeeded) and git diff --check (no issues).
  • Note: a full repository-wide bun test run encountered unrelated environment-sensitive failures in other test areas (lab harness and platform-specific fixtures) that are outside the scope of this focused change.

Codex Task

@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 11b57ed9-902b-44ed-8d20-4e47b52b9237


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 30, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-08-30T05:43:25.661181Z c89ef0d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Aug 30, 2026
@github-actions

github-actions Bot commented Aug 30, 2026

Copy link
Copy Markdown

⏳ DRAFT

  • wrong target branch (main); retarget to dev.

What to do

  • Retarget this PR to dev — all contributions go to dev.

Its title has been prefixed with [WRONG BRANCH].
This pull request was already a draft. Its draft status will be preserved after every issue above is resolved.

@github-actions github-actions Bot changed the title cli: validate /healthz version before displaying (prevent terminal-injection) [WRONG BRANCH] cli: validate /healthz version before displaying (prevent terminal-injection) Aug 30, 2026
@github-actions
github-actions Bot marked this pull request as draft August 30, 2026 05:41

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c89ef0d9c9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const version = typeof body?.version === "string" ? body.version : undefined;
// Whoever holds the port controls this response. Only carry bounded semver text into
// diagnostics; dropping anything else prevents terminal controls reaching human output.
const version = isHealthzVersion(body?.version) ? body.version : undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Sanitize the fallback status health response

This validation only protects versions returned through proxyIdentityAt; collectStatus can still fall back to checkProxyHealth, which interpolates body.version directly into healthLabel and prints it. For example, when a stale PID/runtime record points to an attacker-held fallback port, a mismatched reported PID makes findLiveProxy reject the listener, but selectListenTarget can select that same recorded port and the fallback probe accepts { service: "opencodex", version: <OSC/newline payload> } without PID validation. Apply isHealthzVersion in checkProxyHealth as well and cover this fallback path with a status regression test.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aardvark bug Something isn't working codex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant