Repository navigation
fix(auth): do not accept an empty HTTP key body as a fetched key - #1869
Open
lanbass869-cell wants to merge 1 commit into
Open
lanbass869-cell wants to merge 1 commit into
lanbass869-cell wants to merge 1 commit into
Conversation
fetchKeyOnce turned a 200 with a zero-length body into ("", nil). An
endpoint that answers 200 and then stalls races the client timeout: if the
empty 200 lands first, Do succeeds, io.ReadAll returns nothing, and the
empty string is handed back as the public key. The retry is skipped and the
caller only fails later with "no valid MCP public key found", which points
at the key rather than at the transport.
CI surfaced it twice as key="" err=<nil> requests=1 in
TestHTTPKeyFetcherRetryRecoversAfterAttemptTimeout and
TestHTTPKeyFetcherRetryProductionTimeBudget.
Treat an empty (or whitespace-only) body as a transient failure so the
existing second attempt runs and the error names the real problem.
This branch has not been deployed
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.
fetchKeyOncereturns("", nil)when the well-known endpoint answers200with a zero-length body. It is reachable in production, and it showed up in CI as a flake.What goes wrong
If an endpoint sends the response headers and then stalls, the empty
200can land just as the client timeout fires.Dothen succeeds,io.ReadAllyields nothing, andstrings.TrimSpace("")is handed back as the public key withretryable=false. Consequences:no valid MCP public key found— an error pointing at the key, not at the transport;""is returned toKeyFetcher, where it is only rejected further down the stack.This is not hypothetical. While reviewing the
Testsjob of #1861 it failed twice in the same file, with the same signature, on two different tests:TestHTTPKeyFetcherRetryProductionTimeBudgeterr=<nil> requests=1 elapsed=10.006368148sTestHTTPKeyFetcherRetryRecoversAfterAttemptTimeoutkey="" err=<nil> requests=1requests=1witherr=<nil>is only reachable through the empty-body path: a genuine timeout is an error and triggers the retry.Reproduction
Against the pre-patch code, a server that returns
200with no body:Deterministic, no timing needed.
Fix
After the size check, treat an empty (or whitespace-only) body as a transient failure:
retryable=truemeans the existing second attempt now runs, and if both attempts are empty the returned error names the actual problem instead of surfacing as a key-parsing failure. The success path, the permanent-failure classification and the timeout budget are unchanged.Tests
New
http_empty_body_internal_test.go:requests == httpKeyFetchAttempts)Mutation check: reverting the one condition makes all three fail with
key="" err=<nil>.Locally:
go vetclean,gofmtclean,go test ./internal/api/handlers/v0/auth/ -skip OIDCpasses. The OIDC tests in this package needaccounts.google.comfor provider discovery and cannot run without egress from this machine; that is unrelated to this change and they pass in CI.