security: add domain validation to SIWE authentication examples - #1559
security: add domain validation to SIWE authentication examples#1559zkasuran wants to merge 1 commit into
Conversation
Fixes cross-domain replay attack vulnerability in authenticate-users guide. ## Problem Backend examples only verified cryptographic signature without validating the SIWE message domain. This allows valid signatures from evil.com to be replayed against yourapp.com's /auth/verify endpoint. ## Changes - Replace `verifyMessage` with `verifySiweMessage` in both examples - Add explicit domain parameter validation - Add comment explaining security rationale - Import `verifySiweMessage` from 'viem/siwe' ## Impact Prevents cross-domain replay attacks as required by EIP-4361 spec. Developers following this guide will now ship secure authentication. Fixes base#1502 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
🟡 Heimdall Review Status
|
|
Still at 0/2 reviews, so here is where this stands against current The bug is live. Both backend examples in The patch still applies as written. Master has 202 files changed since this branch's merge base and On the ERC-6492 line earlier in the page, One note on merge order: #1560 was branched off this commit, so its diff contains this change. Merge this one first and #1560 comes down to its own three files, or merge #1560 alone and close this one as included. |
Summary
Fixes cross-domain replay attack vulnerability in the authenticate-users guide backend examples.
Problem (Issue #1502)
The current backend verification code only checks the cryptographic signature without validating the SIWE message domain:
This is insecure. A valid SIWE signature created for
evil.comcan be submitted toyourapp.com's/auth/verifyendpoint and will pass verification, becauseverifyMessageonly validates the cryptographic signature — not whether the message was intended for this domain.EIP-4361 Requirement
EIP-4361 explicitly requires relying parties to validate the
domainfield:Solution
Replace
verifyMessagewithverifySiweMessagewhich validates domain, nonce, and expiry:Changes
verifySiweMessageimport fromviem/siwedomainparameter with commentImpact
Before: Developers following this guide ship authentication endpoints vulnerable to cross-domain replay attacks.
After: Secure authentication that complies with EIP-4361 spec.
Testing
Code follows viem's official API:
Fixes #1502