Repository navigation
Conversation
Check SSE framing before forwarding provider output and mask credentials in passthrough and rewritten frames. Keep bounded diagnostics in attempt logs and reject JSON error envelopes that lack a protocol result field.
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.
Summary
When a client requests a streaming completion, the gateway forwards the provider's event stream to the client. If the provider answers with a 2xx status but the body is not an SSE stream (for example a single JSON error envelope), the gateway currently:
dataof error frames;200 text/event-streamto the client, while the attempt is recorded as a failure (or, after a clean EOF, as a success).Some providers include sensitive request details in such error bodies, including the provider credential used for the request. In that case the credential configured in TokenHub can be returned to any client that is allowed to call the model. A related case exists for non-streaming chat: a 2xx JSON error envelope is returned to the caller as a successful completion.
This change validates the framing of provider streams before anything is written to the client, never forwards raw provider bytes that are not SSE, and masks provider credentials in every byte that is forwarded.
Related Issue
N/A
Changes
Content-Type, so valid SSE labelled asapplication/jsonkeeps working.502, existingprovider_upstream_errorcode, fixed message). The client never sees provider text. A bounded, credential-masked copy of the body is kept only in the attempt log; bodies over the bound are masked entirely rather than truncated.200. The playgroundstartedevent is sent with the first output event.choices,output,content) is absent and the body carries a structured failure signal (non-null top-levelerror,success: false, or a numericcodeof 400 or above). Bodies that contain the result field are returned unchanged.Type of Change
Verification
All commands were run on the branch head, with Go 1.26.9 and golangci-lint v2.12.2 as pinned in CI.
gofmt -l .inbackend/: no output.go vet ./...inbackend/: passed.go test -timeout 30m ./...inbackend/: passed (24 packages, 0 failures).golangci-lint run ./...inbackend/(v2.12.2): 0 issues.node --test tools/*.test.mjs: 205/205 passed.node tools/check-source-lines.mjs,node tools/check-env-contract.mjs,node tools/check-ui-translations.mjs,node tools/check-doc-translations.mjs --base v0.11.0 --head HEAD: passed.git diff --check: passed.text/event-streamandapplication/json, with and without trailing newlines;Content-Type; BOM, heartbeats, CRLF and extension fields; unframed lines inside a stream;[DONE];200now expect the uncommitted failure. The quota release, TTFB and interruption metric assertions are unchanged and pass.v0.11.0base as well, because they expect diagnostics from a newer standard library. They pass on Go 1.26.9 and are unrelated to this change.Compatibility, Security, and Operations
502JSON error before any stream bytes, instead of a200event stream containing the provider's raw body. A non-streaming 2xx error envelope without a result field now returns502instead of200. Valid streams and completions are unchanged.200on the first provider output instead of before reading the provider body. Clients that relied on receiving headers before the first event will receive them slightly later.Checklist
.envfiles, databases, backups, or runtime logs are included.start.sh, and deployment documentation where applicable. (No environment variable changes.)data/model-catalog.yamlremains tracked and catalog changes were reviewed where applicable. (Not changed.)git diff --checkpasses.