Skip to content

fix!: close the audit findings across auth, media and the surfaces - #16

Merged
dinhdev666 merged 1 commit into
mainfrom
fix/audit-hardening
Dec 3, 2026
Merged

dinhdev666 merged 1 commit into
mainfrom
fix/audit-hardening

Conversation

@dinhdev666

Copy link
Copy Markdown
Owner

What this changes

A full read-only audit of the gateway (six independent reviews covering auth and
HTTP hardening, the media path, the upstream lifecycle, the streaming hot paths,
the public surface adapters and documentation/test drift) produced 53 accepted
findings. This pull request closes all of them in one logical change, with a
regression test per fix.

Security

  • The spawned opencode serve password is redacted from <dataDir>/logs/*.log,
    from the spawn-failure messages and from GET /admin/status.
  • Media downloads no longer leak an errno port-scan oracle or a URL carrying
    user:password@; a redirect the scheme allow-list rejects no longer parks a
    keep-alive socket; name resolution counts against mediaFetchTimeoutMs and the
    caller's abort signal; a local file is read in bounded chunks; the attachment
    size cap is applied before a base64 decode; a declared MIME value must be an
    RFC 6838 type/subtype token; isWithinRoots() accepts dot-prefixed children.
  • The undocumented scheme-less Authorization transport is gone; failed
    authentication is rate limited (always-on bucket) and audited at warn;
    OPENCODE_TRUST_PROXY accepts a hop count or a CIDR list;
    OPENCODE_ADMIN_API_KEYS adds an operator tier for /admin/*;
    OPENCODE_BODY_TIMEOUT_MS bounds body receipt; pnpm setup writes .env with
    mode 0600; .dockerignore covers credential files.

Performance

  • A stalled SSE consumer no longer grows the write queue: the writer records the
    stall, destroys the socket and aborts the turn.
  • The per-turn event queue drains in O(1) and is bounded (MAX_QUEUED_EVENTS),
    failing the turn through the existing event_stream_lost path.
  • SessionStore.commit() no longer traverses or sorts the whole cache; the
    eviction pass finds the least recently used idle record in one walk.
  • A catalogue retained after an empty upstream answer now expires with the TTL.
  • The persist debounce can no longer be starved; the tool bridge, the effort
    mapping and the native-tool name lookup stop rescanning.

Correctness

  • /v1/responses emits the unseen suffix when it adopts consolidated
    text_end/reasoning_end, and keeps media inside function_call_output.
  • The tool bridge rejects envelopes naming tools the request never declared.
  • Anthropic thinking, empty input/messages (array and literal string), chat
    best_of/suffix and Responses tool_choice are validated with the
    documented code and param.
  • A failing child-log write stream no longer aborts the process; a request
    timeout re-verifies the endpoint (reprobe()) instead of SIGKILLing the shared
    server; stop() terminates a child still inside its readiness window; the
    readiness probe distinguishes unauthorized from absent;
    SIGINT/SIGTERM/SIGHUP are handled from before the upstream warm-up.

Docs — docs/API.md, docs/ARCHITECTURE.md, docs/CONFIGURATION.md,
docs/VERIFICATION.md, README.md and .env.example are re-aligned, and the
docs-consistency guard now compares the documented GET / example with the live
response body instead of with the router table (the two used to cancel out).

Verification

pnpm typecheck    # clean
pnpm build        # clean
pnpm test         # 25 files, 657 passed, 5 skipped
pnpm smoke:dist   # dist/index.js answered /health with version 1.0.0
pnpm audit --prod # no known vulnerabilities

Breaking changes

  • A scheme-less Authorization header is no longer accepted.
  • The gateway refuses to start while the built-in sk-dummy-123 key is accepted
    on a non-loopback HOST (the Docker quickstart now generates a real key).
  • OPENCODE_TRUST_PROXY=1 now means "trust one hop" instead of "trust every
    hop"; use true for the previous behaviour.

A full read-only audit of the gateway found defects in the request path,
the media resolver, the upstream lifecycle, the streaming hot paths and
the public wire formats. This closes them and adds the regression tests
that pin every fix.

Security: the spawned server password is redacted from its log file,
from spawn errors and from GET /admin/status; media download failures
no longer expose an errno oracle or a URL carrying credentials; a
redirect can no longer park a keep-alive socket; name resolution counts
against the fetch budget; a local file is read in bounded chunks; the
base64 cap is applied before decoding; a declared MIME value must be a
type/subtype token; isWithinRoots() accepts dot-prefixed children; the
undocumented scheme-less Authorization transport is gone; failed
authentication is rate limited and audited at warn; OPENCODE_TRUST_PROXY
accepts a hop count or a CIDR list; OPENCODE_ADMIN_API_KEYS adds an
operator tier for /admin/*; OPENCODE_BODY_TIMEOUT_MS bounds body
receipt; pnpm setup writes .env with mode 0600 and .dockerignore covers
credential files.

Performance: a stalled SSE consumer no longer grows the write queue (the
socket is destroyed and the turn aborted); the per-turn event queue
drains in O(1) and is bounded; the session store no longer walks the
cache on every commit; a catalogue retained after an empty upstream
answer expires with the TTL; the persist debounce can no longer be
starved; the tool bridge and the model listing stop rescanning.

Correctness: /v1/responses emits the unseen suffix when it adopts
consolidated text and keeps media inside function_call_output; the tool
bridge rejects envelopes naming undeclared tools; Anthropic thinking,
empty input, chat best_of/suffix and Responses tool_choice are
validated; a failing child log stream no longer kills the process; a
request timeout re-verifies the endpoint instead of SIGKILLing the
shared server; SIGINT/SIGTERM/SIGHUP are handled from before the
upstream warm-up.

Docs: API.md, ARCHITECTURE.md, CONFIGURATION.md, VERIFICATION.md, the
README and .env.example are re-aligned with the code, and the
docs-consistency guard now compares the GET / example with the live
body.

Verified: pnpm typecheck, pnpm build, pnpm test (25 files, 657 passed,
5 skipped), pnpm smoke:dist and pnpm audit --prod.

BREAKING CHANGE: a scheme-less `Authorization` header is no longer
accepted; the gateway refuses to start while the built-in `sk-dummy-123`
key is accepted on a non-loopback HOST; `OPENCODE_TRUST_PROXY=1` now
means "trust one hop" instead of "trust every hop" (use `true` for the
previous behaviour).
@dinhdev666
dinhdev666 merged commit 0a0f6e6 into main Dec 3, 2026
5 checks passed
@dinhdev666
dinhdev666 deleted the fix/audit-hardening branch December 3, 2026 09:34
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.

1 participant