Skip to content

fix: reject malformed CAIP-10 addresses in setCaipAddress - #5634

Merged
svenvoskamp merged 2 commits into
chore/khizr-fixesfrom
chore/khizr-fixes-REOWN-4448
Apr 13, 2026
Merged

fix: reject malformed CAIP-10 addresses in setCaipAddress#5634
svenvoskamp merged 2 commits into
chore/khizr-fixesfrom
chore/khizr-fixes-REOWN-4448

Conversation

@Khizr97

@Khizr97 Khizr97 commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Prevents malformed CAIP-10 addresses from entering AppKit state when a wallet emits an empty address string (REOWN-4448).

Technical Report

Problem

When a wallet connector emits an empty string "" as the account address (observed sporadically with injected wallets and WalletConnect during reconnection/network switching), AppKit stores a malformed CAIP-10 address like "eip155:42161:" in state. This propagates through balance fetching, identity sync, and SIWE — all operating on an empty address.

Root Cause Analysis

syncAccountInfo in appkit-base-client.ts constructs the CAIP-10 address via string interpolation: `${chainNamespace}:${newChainId}:${address}`. With an empty address, this produces "eip155:42161:" — technically a string but invalid CAIP-10. setCaipAddress stored this directly without validation. Downstream, getPlainAddress() returns "", and consumers operate on a garbage address.

ParseUtil.parseCaipAddress already validates CAIP-10 format, but setCaipAddress bypassed it entirely — doing raw interpolation and direct state assignment.

Approach & Reasoning

Added validation guard in setCaipAddress — the single convergence point before any CAIP-10 value enters state. The guard splits on ":" and checks for exactly 3 non-empty parts (namespace:chainId:address). Malformed values are rejected with a console.warn for debuggability.

Why setCaipAddress and not the callers: There are multiple code paths that call setCaipAddress (syncAccountInfo, onAuthProviderConnected, adapter callbacks). Guarding at the convergence point covers all of them with one check.

Why silent reject with warning (not throw): The wallet is the source of the bad data, not the app. Throwing would crash the connection flow. Silently rejecting keeps the app functional with whatever address was previously in state. The console.warn ensures the issue is visible for debugging.

Format validation: Splits on ":" and checks parts.length === 3 && !parts.some(p => !p). This correctly handles:

  • EVM: "eip155:1:0xABC..." → passes (3 non-empty parts)
  • Solana: "solana:5eykt4...:SoLAddr..." → passes
  • Bitcoin: "bip122:000000...:bc1q..." → passes
  • Malformed: "eip155:42161:" → rejected (empty 3rd part)
  • Null: allowed through (used for disconnect)

Works with REOWN-4447 fix: Even if toChecksummedAddress returns an empty/undefined address, this guard catches it before it enters state.

Verification

  • 75/75 appkit public-methods tests pass
  • Type check clean
  • No addresses with colons in any supported blockchain format (EVM hex, Solana base58, Bitcoin bech32)

Test plan

  • Connect wallet — verify address correctly stored in state
  • Simulate empty address emission — verify console.warn and no malformed CAIP-10 in state
  • Disconnect wallet — verify null caipAddress still works

🤖 Generated with Claude Code

When a wallet emits an empty string as the account address, AppKit
would store a malformed CAIP-10 address like "eip155:42161:" in state.
This propagated through balance fetching, identity sync, and SIWE,
all operating on an empty address. Added a validation guard in
setCaipAddress that rejects any CAIP-10 string that doesn't have
exactly 3 non-empty colon-separated parts.

Closes REOWN-4448

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@linear

linear Bot commented Apr 9, 2026

Copy link
Copy Markdown

@changeset-bot

changeset-bot Bot commented Apr 9, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 6f53704

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel

vercel Bot commented Apr 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
appkit-demo Ready Ready Preview, Comment Apr 9, 2026 10:56pm
appkit-gallery Ready Ready Preview, Comment Apr 9, 2026 10:56pm
appkit-headless-sample-app Ready Ready Preview, Comment Apr 9, 2026 10:56pm
appkit-laboratory Ready Ready Preview, Comment Apr 9, 2026 10:56pm
9 Skipped Deployments
Project Deployment Actions Updated (UTC)
appkit-basic-example Ignored Ignored Apr 9, 2026 10:56pm
appkit-basic-sign-client-example Ignored Ignored Apr 9, 2026 10:56pm
appkit-basic-up-example Ignored Ignored Apr 9, 2026 10:56pm
appkit-ethers5-bera Ignored Ignored Apr 9, 2026 10:56pm
appkit-nansen-demo Ignored Ignored Apr 9, 2026 10:56pm
appkit-wagmi-cdn-example Ignored Ignored Apr 9, 2026 10:56pm
ethereum-provider-wagmi-example Ignored Ignored Apr 9, 2026 10:56pm
next-wagmi-solana-bitcoin-example Ignored Ignored Apr 9, 2026 10:56pm
vue-wagmi-example Ignored Ignored Apr 9, 2026 10:56pm

Request Review

@github-actions

github-actions Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CTA ✍️ ✅
Posted by the CLA Assistant Lite bot.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Khizr97

Khizr97 commented Apr 13, 2026

Copy link
Copy Markdown
Contributor Author

I have read the CTA Document and I hereby sign the CTA

@svenvoskamp
svenvoskamp merged commit dc4067e into chore/khizr-fixes Apr 13, 2026
17 of 18 checks passed
@svenvoskamp
svenvoskamp deleted the chore/khizr-fixes-REOWN-4448 branch April 13, 2026 16:29
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants