fix: add runtime validation for ConnectionMode (WAPI-1129)#75
Merged
chakra-guy merged 1 commit intomainfrom Feb 27, 2026
Merged
fix: add runtime validation for ConnectionMode (WAPI-1129)#75chakra-guy merged 1 commit intomainfrom
chakra-guy merged 1 commit intomainfrom
Conversation
a4884b7 to
06bb51b
Compare
5ec0e2d to
5abc9ea
Compare
adonesky1
reviewed
Feb 25, 2026
adonesky1
previously approved these changes
Feb 25, 2026
06bb51b to
b458794
Compare
ConnectionMode was a TypeScript-only type with no runtime enforcement. A malformed session request with an invalid mode (e.g. "admin") would silently fall through to the UntrustedConnectionHandler. Now both WalletClient and DappClient validate the mode at connect-time before any state transition, and throw a clear error for invalid values. Exports CONNECTION_MODES const and isValidConnectionMode() type guard from core for downstream consumers.
5abc9ea to
b20564c
Compare
wenfix
approved these changes
Feb 27, 2026
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
ConnectionModevalues at connect-time in bothWalletClientandDappClientCONNECTION_MODESconst array andisValidConnectionMode()type guard from core"admin"would silently fall through to theUntrustedConnectionHandlervia the else branchBackground
ConnectionModewas a TypeScript-only type ("trusted" | "untrusted") with no runtime enforcement. SinceSessionRequest.modecan come from external sources (e.g. a QR code, deep link, or cross-origin message), a malformed value would bypass type safety at runtime. The Cyfrin audit flagged this as needing runtime validation.Changes
packages/core/src/domain/connection-mode.ts: AddedCONNECTION_MODESconst array andisValidConnectionMode()type guardpackages/core/src/index.ts: Exports the new symbolspackages/wallet-client/src/client.ts: Validatesrequest.modebefore handler selectionpackages/dapp-client/src/client.ts: Validatesmodebefore creating session requestpackages/core/CHANGELOG.md: Documents the new exportsTest plan
yarn buildpassesyarn test:unitpasses (68/68 tests)Note
Low Risk
Low risk: small, localized change that adds runtime guarding of externally-sourced
modevalues and only affects connect-time error handling/flow selection.Overview
Adds runtime validation for
ConnectionModeby introducingCONNECTION_MODESand theisValidConnectionMode()type guard in core and exporting them publicly.Updates
DappClient.connect()andWalletClient.connect()to reject invalidmodevalues (throwingSessionError) before enteringCONNECTINGand selecting a connection handler, preventing unexpected fall-through to the untrusted flow.Written by Cursor Bugbot for commit b20564c. This will update automatically on new commits. Configure here.