Repository navigation
fix!: close the audit findings across auth, media and the surfaces - #16
Merged
Merged
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
opencode servepassword is redacted from<dataDir>/logs/*.log,from the spawn-failure messages and from
GET /admin/status.user:password@; a redirect the scheme allow-list rejects no longer parks akeep-alive socket; name resolution counts against
mediaFetchTimeoutMsand thecaller'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/subtypetoken;isWithinRoots()accepts dot-prefixed children.Authorizationtransport is gone; failedauthentication is rate limited (always-on bucket) and audited at
warn;OPENCODE_TRUST_PROXYaccepts a hop count or a CIDR list;OPENCODE_ADMIN_API_KEYSadds an operator tier for/admin/*;OPENCODE_BODY_TIMEOUT_MSbounds body receipt;pnpm setupwrites.envwithmode
0600;.dockerignorecovers credential files.Performance
stall, destroys the socket and aborts the turn.
MAX_QUEUED_EVENTS),failing the turn through the existing
event_stream_lostpath.SessionStore.commit()no longer traverses or sorts the whole cache; theeviction pass finds the least recently used idle record in one walk.
mapping and the native-tool name lookup stop rescanning.
Correctness
/v1/responsesemits the unseen suffix when it adopts consolidatedtext_end/reasoning_end, and keeps media insidefunction_call_output.thinking, empty input/messages (array and literal string), chatbest_of/suffixand Responsestool_choiceare validated with thedocumented code and
param.timeout re-verifies the endpoint (
reprobe()) instead of SIGKILLing the sharedserver;
stop()terminates a child still inside its readiness window; thereadiness probe distinguishes
unauthorizedfromabsent;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.mdand.env.exampleare re-aligned, and thedocs-consistency guard now compares the documented
GET /example with the liveresponse body instead of with the router table (the two used to cancel out).
Verification
Breaking changes
Authorizationheader is no longer accepted.sk-dummy-123key is acceptedon a non-loopback
HOST(the Docker quickstart now generates a real key).OPENCODE_TRUST_PROXY=1now means "trust one hop" instead of "trust everyhop"; use
truefor the previous behaviour.