fix: parse SIWE Chain ID from the structured field only - #424
Conversation
A statement that mentioned another chain used to win the first regex match and send personal_sign to the wrong network.
There was a problem hiding this comment.
🟡 Changes recommended
The updated chain-id parser can now return non-numeric values if the structured Chain ID: line contains trailing text, which regresses prior digits-only behavior and can break downstream chain-id validation/routing.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR fixes SIWE chain-id extraction so getChainIdFromMessage no longer picks up Chain ID: <digits> occurrences embedded in the free-form statement, and instead only considers lines that start with Chain ID: (the structured field).
Changes:
- Update
AuthSignature.getChainIdFromMessageto scan line-by-line for aChain ID:-prefixed field. - Add a regression test where the statement mentions another chain id, ensuring the structured
Chain IDis used. - Document the fix in
packages/reown_signchangelog (1.4.1).
File summaries
| File | Description |
|---|---|
| packages/reown_sign/lib/utils/auth_signature.dart | Adjusts SIWE chain-id parsing to avoid matching statement text. |
| packages/reown_sign/test/auth/signature_test.dart | Adds coverage for statements that mention a different chain id. |
| packages/reown_sign/CHANGELOG.md | Notes the SIWE chain-id parsing fix in a new release entry. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
@ignaciosantise this is the greedy SIWE regex — a statement that mentions another chain was winning over the real |
|
@ignaciosantise still merge-ready after catching latest develop. Please approve/apply when you can. |
Summary
Hey @ignaciosantise / Reown team —
getChainIdFromMessagewas taking the firstChain ID: <digits>anywhere in the SIWE text.If the statement says something like "Please use Chain ID: 137", AppKit then sends
personal_signon Polygon even when the real field isChain ID: 1. This now only reads lines that start withChain ID:.Test plan
cd packages/reown_sign && flutter test test/auth/signature_test.dartChain IDline