Repository navigation
Conversation
idtoken.Validator.Validate() panicked with an unrecovered runtime error when given a JWT signed with alg: ES256 whose signature segment decodes to fewer than 32 bytes. Any service using this package to validate incoming Google-issued ID tokens could be crashed by a single malformed ~120-byte JWT. Root cause: validateES256 sliced sig[:es256KeySize] and sig[es256KeySize:] with no length check. findMatchingKey only validates that the JWT's kid header matches a known (public) key ID before this point -- it does not validate the signature -- so any attacker who fetches a real kid from the public JWKS endpoint can reach the vulnerable slice with a crafted short signature. Fix: validate len(sig) == es256KeySize*2 before slicing, returning an error instead of panicking. This also fixes a related correctness issue where signatures longer than 64 bytes were silently truncated without error. Two regression tests added: short signature (panic case) and overlong signature (truncation case).
|
Hi Team, Just checking in to see if you've had a chance to look at the patch strategy for this. I'm happy to spin up the code changes for the fix in a private fork if that helps speed things up. Thanks again for your time! |
|
Hi Team, Just checking in to see if you've had a chance to look at the patch strategy for this. I'm happy to spin up the code changes for the fix in a private fork if that helps speed things up. |
|
Hi Team, Just checking in to see if you've had a chance to look at the patch strategy for this. |
1 similar comment
|
Hi Team, Just checking in to see if you've had a chance to look at the patch strategy for this. |
|
This is still present in |
|
This is still present on Some detail that may help review:
The fix and the regression test in this PR look correct to us. It would be good to see it merged. This comment was written by Claude (Anthropic's AI assistant) on behalf of the account posting it. We found the issue during an internal review of the dependencies we ship, and confirmed it against the current source. |
shollyman
left a comment
There was a problem hiding this comment.
Thanks for the contribution, sorry this languished. I've made some changes to consolidate the test code a bit.
This PR propagates similar length validation from googleapis/google-api-go-client#3668 into the corresponding package in google-cloud-go.
Problem
idtoken.Validator.Validate()panics with an unrecovered runtime error when given a JWT signed withalg: ES256whose signature segment decodes to fewer than 32 bytes. Any service using this package to validate incoming Google-issued ID tokens (e.g. Cloud Run, Cloud Functions, custom services authenticating callers via bearer tokens) can be crashed by a single malformed ~120-byte JWT.Root Cause
idtoken/validate.go,validateES256:findMatchingKeyonly checks that the JWT'skidheader matches a known key ID — it does not validate the signature at that point. The JWKS endpoint (googleIAPCertsURL) is public and unauthenticated by design, so any attacker can retrieve a real, currently validkidwith a single unauthenticated GET request, then craft a JWT with thatkidand a signature under 32 bytes to trigger the panic.Fix
Adds an exact-length check before slicing:
This also incidentally fixes a related correctness issue: signatures longer than 64 bytes were previously silently truncated to the first 64 bytes without error (only the exact-length check catches both directions).
Testing
Two new regression tests in
idtoken/validate_test.go:TestValidateES256_ShortSignature: a 3-byte signature must return an error, not panicTestValidateES256_OverlongSignature: a 65-byte signature must also return an errorBoth use the package's real, unmodified, exported
Validator.Validate()entry point via the existingRoundTripFn/commonTokentest helpers — no reimplementation.