Skip to content

fix(swift-sdk): reject NUL bytes in createWallet(mnemonic:) #5758

Open

Description

@xdustinface

PlatformWalletManager.createWallet(mnemonic:network:name:createDefaultAccounts:birthHeight:) passes the phrase to platform_wallet_manager_create_wallet_from_mnemonic_with_birth_height through withCString without checking for NUL bytes. Rust reads the C string only up to the first NUL, so a phrase followed by a NUL and junk creates a wallet from the valid prefix instead of failing.

The other Swift wrappers that take a phrase or an address already reject this with KeyDerivation.requireNoNUL. The async overload of createWallet(mnemonic:) needs the same check if it does not go through the synchronous one.

Fix

Call try KeyDerivation.requireNoNUL(mnemonic, "Mnemonic") before the C-string conversion, and add a test that a phrase with an embedded NUL throws.

Found by CodeRabbit on #5728. The gap already exists on v5.1-dev and is outside that PR's diff.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions