security: add domain validation to SIWE authentication examples#1559
Open
cryptoasuran wants to merge 1 commit into
Open
security: add domain validation to SIWE authentication examples#1559cryptoasuran wants to merge 1 commit into
cryptoasuran 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>
Collaborator
🟡 Heimdall Review Status
|
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.
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