Skip to content

fix(siwe): return false instead of panicking on malformed signatures - #2625

Merged
cstockton merged 3 commits into
supabase:masterfrom
samarth70:fix/siwe-verify-signature-no-panic
Jul 14, 2026
Merged

cstockton merged 3 commits into
supabase:masterfrom
samarth70:fix/siwe-verify-signature-no-panic

Conversation

@samarth70

Copy link
Copy Markdown
Contributor

Problem

SIWEMessage.VerifySignature (internal/utilities/siwe/parser.go) returns bool, but panics on two attacker-controlled inputs instead of returning false:

sig, err := hexutil.Decode(signatureHex)
if err != nil || len(sig) != 65 {
    panic("siwe: signature must be a 65-byte hex string")
}
...
pubKey, err := crypto.Ecrecover(hash, signature)
if err != nil {
    panic("siwe: failed to recover public key: " + err.Error())
}

Both are reachable from the public, unauthenticated endpoint POST /token?grant_type=web3 (web3GrantEthereum). The caller's pre-check only gates on length via strings.TrimPrefix(params.Signature, "0x") — which is a no-op when the 0x prefix is absent and does not validate hex-ness — so malformed signatures reach VerifySignature and trigger a panic.

The recoverer middleware 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 clean 400 invalid_grant that a bad signature should produce. That's an API-contract bug plus a stack-trace log-flooding vector on an unauthenticated endpoint.

Fix

Return false on both error paths, matching the sibling Solana verifier internal/utilities/siws/parser.go (SIWSMessage.VerifySignature), which never panics. Behavior-only change; no signature/API change.

Tests

Adds TestVerifySignatureRejectsMalformedInput covering empty, missing-0x-prefix, non-hex, wrong-length, and unrecoverable signatures — asserting require.NotPanics + require.False. The unrecoverable/wrong-length/missing-prefix cases exercise both former panic paths.

Verified with go test ./internal/utilities/siwe/ — passes on the fix and panics/fails on the old code; gofmt and go vet clean. The siwe package is pure (no DB needed to test).

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.
@samarth70
samarth70 requested a review from a team as a code owner July 13, 2026 23:59

@cstockton cstockton left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

I checked that when VerifySignature returns false all callers return an error, merging this.

@cstockton
cstockton merged commit c3005a4 into supabase:master Jul 14, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants