fix(openai): sanitize websocket errors before request logging - #203
Open
warelik wants to merge 1 commit into
Open
fix(openai): sanitize websocket errors before request logging#203warelik wants to merge 1 commit into
warelik wants to merge 1 commit into
Conversation
forwardResponsesWebsocket passed the executor's ErrorMessage and the terminal error payload message to LoggingAPIResponseError verbatim, before the redaction that writeResponsesWebsocketTerminalError applies to the client-facing frame. With RequestLog enabled the request log then stored the raw upstream body, which can echo the credential sent upstream. Wrap both call sites in sanitizeOpenAIErrorMessage, the same trust-boundary sanitizer the other OpenAI handlers use before writing error responses. Covered by TestForwardResponsesWebsocketSanitizesLoggedUpstreamError and TestForwardResponsesWebsocketSanitizesLoggedErrorPayload, which drive the forwarder over a real websocket pair with a credential-bearing upstream error and assert the recorded API_RESPONSE_ERROR is redacted.
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.
Problem
forwardResponsesWebsocketpassed two upstream-derived errors toLoggingAPIResponseErrorverbatim, before the redaction thatwriteResponsesWebsocketTerminalErrorapplies to the client-facing frame:sdk/api/handlers/openai/openai_responses_websocket_forward.go:69), anderrorevent payload (:132).With
RequestLogenabled the request logger stores whatever it receives (sdk/api/handlers/handlers_errors.go:164-170), so a raw upstream body could land in the log — including a credential the upstream echoed back.Surfaced by the upstream review at router-for-me/CLIProxyAPI#4881 (discussion_r3827803235); the same code already lives on
mainhere, so this is the Plus-side hardening for it.Fix
sanitizeResponsesStreamErrorMessage, the same trust-boundary sanitizer used elsewhere in this package.redactResponsesStreamErrorTextnow applies the bearer pattern BEFORE the key/value pattern (sdk/api/handlers/openai/openai_responses_handlers.go). Previously the key/value pattern matchedBeareritself as the value of anAuthorization:header and redacted only that word, leaving the token behind in the clear.The locally constructed
stream closed before response.completedmessage is intentionally left unsanitized — it contains no upstream content.Tests
TestForwardResponsesWebsocketSanitizesLoggedUpstreamErrorandTestForwardResponsesWebsocketSanitizesLoggedErrorPayload(new fileopenai_responses_websocket_forward_sanitization_test.go) drive the forwarder over a real websocket pair with a credential-bearing upstream error and assert the recordedAPI_RESPONSE_ERRORis redacted.Reverse bite-checks:
With the fix,
go build ./...,go vet ./sdk/api/handlers/openai/...andgo test -count=1 ./sdk/api/handlers/openai/...are green.