Skip to content

uncaught TypeError when trying to load digit string as a public key #2077

@simonLeary42

Description

@simonLeary42

using phpseclib v3.0.43

phpseclib3\Crypt\PublicKeyLoader\PublicKeyLoader::load('123');

warning:

.../vendor/phpseclib/phpseclib/phpseclib/Crypt/Common/Formats/Keys/JWK.php:53
Attempt to read property "keys" on int

exception:

TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given
.../phpseclib/phpseclib/phpseclib/Crypt/Common/Formats/Keys/JWK.php:53
.../phpseclib/phpseclib/phpseclib/Crypt/EC/Formats/Keys/JWK.php:46
.../phpseclib/phpseclib/phpseclib/Crypt/Common/AsymmetricKey.php:150
.../phpseclib/phpseclib/phpseclib/Crypt/PublicKeyLoader.php:39

similar to #2076. It seems stupid but the legacy codebase I inherited is checking if an SSH key is valid based on whether or not PublicKeyLoader::load throws an exception, with arbitrary user input.

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