Repository navigation
fix(siwe): return false instead of panicking on malformed signatures - #2625
Merged
cstockton merged 3 commits intoJul 14, 2026
Merged
Conversation
SIWEMessage.VerifySignature is a bool verifier, but it panicked on two attacker-controlled inputs: a signature that isn't a 65-byte hex string, and one that fails public-key recovery. Both are reachable from the public, unauthenticated POST /token?grant_type=web3 endpoint (the caller's length gate uses strings.TrimPrefix, which is a no-op without a 0x prefix and doesn't validate hex). The recoverer middleware catches the panic and returns HTTP 500 with a logged stack trace instead of the intended 400 invalid_grant — an API-contract bug and a log-flooding vector. Return false on both paths, matching the sibling internal/utilities/siws verifier, which never panics. Add TestVerifySignatureRejectsMalformedInput covering empty, missing-0x-prefix, non-hex, wrong-length, and unrecoverable signatures (require.NotPanics + require.False). Verified: passes on the fix, panics/fails on the old code; gofmt and go vet clean.
cstockton
approved these changes
Jul 14, 2026
cstockton
left a comment
Contributor
There was a problem hiding this comment.
Thanks for your contribution!
I checked that when VerifySignature returns false all callers return an error, merging this.
cstockton
pushed a commit
that referenced
this pull request
Jul 20, 2026
🤖 I have created a release *beep* *boop* --- ## [2.193.1](v2.193.0...v2.193.1) (2026-07-16) ### Bug Fixes * build darwin-arm64 release binaries with GOOS=darwin ([#2618](#2618)) ([318b4d1](318b4d1)) * ensure legacy refresh token revoked ([#2624](#2624)) ([8748000](8748000)) * **oauth:** prevent authorization-code replay race at /oauth/token ([#2612](#2612)) ([bdbf01e](bdbf01e)) * **siwe:** return false instead of panicking on malformed signatures ([#2625](#2625)) ([c3005a4](c3005a4)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: supabase-releaser[bot] <223506987+supabase-releaser[bot]@users.noreply.github.com>
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
SIWEMessage.VerifySignature(internal/utilities/siwe/parser.go) returnsbool, but panics on two attacker-controlled inputs instead of returningfalse:Both are reachable from the public, unauthenticated endpoint
POST /token?grant_type=web3(web3GrantEthereum). The caller's pre-check only gates on length viastrings.TrimPrefix(params.Signature, "0x")— which is a no-op when the0xprefix is absent and does not validate hex-ness — so malformed signatures reachVerifySignatureand trigger a panic.The
recoverermiddleware catches it, so the process doesn't crash, but it converts the panic into an HTTP 500 with a logged stack trace rather than the clean400 invalid_grantthat a bad signature should produce. That's an API-contract bug plus a stack-trace log-flooding vector on an unauthenticated endpoint.Fix
Return
falseon both error paths, matching the sibling Solana verifierinternal/utilities/siws/parser.go(SIWSMessage.VerifySignature), which never panics. Behavior-only change; no signature/API change.Tests
Adds
TestVerifySignatureRejectsMalformedInputcovering empty, missing-0x-prefix, non-hex, wrong-length, and unrecoverable signatures — assertingrequire.NotPanics+require.False. Theunrecoverable/wrong-length/missing-prefixcases exercise both former panic paths.Verified with
go test ./internal/utilities/siwe/— passes on the fix and panics/fails on the old code;gofmtandgo vetclean. Thesiwepackage is pure (no DB needed to test).