fix: strip plaintext API keys from usage SSE payloads - #1410
Open
dev-Vortex51 wants to merge 1 commit into
Open
dev-Vortex51 wants to merge 1 commit into
dev-Vortex51 wants to merge 1 commit into
Conversation
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.
Overview
This PR removes the plaintext gateway API key from usage SSE payloads. Previously,
handleProxypassedapiKey: apiKeyHeaderintodefaultUsageSseBroadcaster.emitForUser, andUsageSseEventPayloaddeclared anapiKeyfield — so every live dashboard stream carried the raw key. This change drops theapiKeyfield from the payload type, emits onlyapiKeyIdplus a masked prefix, updates the SSE docs, and adds a regression test that fails if the key string appears in any emitted event.Related Issue
Changes
🔒 SSE Payload Redaction
[MODIFY]
src/routes/usage/sse.tsapiKeyfield fromUsageSseEventPayloadso the type no longer permits a plaintext key.apiKeyIdand a masked key prefix (e.g.sk-…abcd) in usage events.[MODIFY]
src/routes/proxyRoutes.tsapiKey: apiKeyHeaderintodefaultUsageSseBroadcaster.emitForUser.apiKeyIdand the masked prefix instead, keeping the raw header confined to the proxy request scope.🧪 Regression Tests
[MODIFY]
src/routes/usage/sse.test.tsapiKeyIdand the masked prefix but never the plaintext key.UsageSseEventPayloadtype.[ADD]
src/__tests__/api-key-redaction-regression.test.ts📝 Docs
docs/usage-sse.mdapiKeyand the presence ofapiKeyId+ masked prefix.Verification Results
apiKeyIdbut not the plaintext keyapiKeyremoved from payload; onlyapiKeyId+ masked prefix emittedapiKeyfieldUsageSseEventPayloadupdated insrc/routes/usage/sse.tsdocs/usage-sse.mdreflects the new schemaapiKey, documentapiKeyId+ masked prefixsrc/__tests__/api-key-redaction-regression.test.tsSecurity & Failure-Mode Handling
apiKeyfield) and at the emit site (onlyapiKeyId+ masked prefix), so a future caller cannot reintroduce the key without a type error.Compatibility
apiKey; consumers should switch toapiKeyIdand the masked prefix. Docs are updated accordingly.Closes #1264