Repository navigation
fix(evm): reject malformed CAIP-2 network identifiers in getEvmChainId - #3521
Merged
phdargen merged 3 commits intoSep 21, 2026
Merged
Conversation
|
@HereForTheTechNFT is attempting to deploy a commit to the Coinbase Team on Vercel. A member of the Team first needs to authorize it. |
phdargen
approved these changes
Sep 21, 2026
phdargen
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for the contribution @HereForTheTechNFT
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.
Description
getEvmChainIdparses the CAIP-2 reference withparseInt(idStr, 10), which stops at the first non-digit instead of rejecting the input, so a malformed network resolves to a chain ID the caller never supplied:networkGetEvmChainIdget_evm_chain_ideip155:0x21050ValueErroreip155:8453abc8453ValueErroreip155:8453.98453ValueErroreip155:1e31ValueErroreip155:90071992547409939007199254740992big.Int)NetworkSchemaV2only requires a colon, so these reach the mechanism. The value is then signed into the EIP-712 domain —getBatchSettlementEip712Domain(getEvmChainId(network))inbatch-settlement/server/verify.tsandbatch-settlement/utils.ts, and the Permit2 / EIP-3009 domains viashared/permit2.ts— and selects the RPC inshared/rpc.ts.The fix requires a bare decimal reference.
/^eip155:(\d+)$/is the same pattern the SIWX extension already uses (packages/extensions/src/sign-in-with-x/evm.ts). Chain IDs pastNumber.MAX_SAFE_INTEGERnow throw instead of rounding, sincenumbercannot represent what Go'sbig.Intand Python'sintcan.Well-formed identifiers are unaffected and both existing error messages are unchanged.
Tests
pnpm --filter @x402/evm test: 40 files, 1129 passed (1121 onmain, +8 new).main(AssertionError: expected [Function] to throw an error) and pass with the fix.eslintandprettier --checkclean for the package.Not run locally: the full
pnpm testmatrix and the Go/Python suites (unchanged here) — CI covers those. I also grepped every"eip155:…"literal underpackages/; the only ones the stricter pattern rejects are negative-test fixtures.Checklist
AI-assisted, per AI-Assisted Contributions: the patch was produced with Claude. The diff, the before/after behaviour table and the local test runs were reviewed before marking this ready.