Skip to content

Commit b705c53

Browse files
authored
Prevent PublicKeyCredentialLoader::load from throwing \JsonException. Use of library exception instead (#365)
1 parent 074740c commit b705c53

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/webauthn/src/PublicKeyCredentialLoader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function load(string $data): PublicKeyCredential
119119
$this->logger->error('An error occurred', [
120120
'exception' => $throwable,
121121
]);
122-
throw $throwable;
122+
throw InvalidDataException::create($data, 'Unable to load the data', $throwable);
123123
}
124124
}
125125

tests/library/Functional/AttestationTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
namespace Webauthn\Tests\Functional;
66

77
use ParagonIE\ConstantTime\Base64UrlSafe;
8-
use RangeException;
98
use Webauthn\AttestedCredentialData;
109
use Webauthn\AuthenticatorAttestationResponse;
1110
use Webauthn\AuthenticatorData;
11+
use Webauthn\Exception\InvalidDataException;
1212
use Webauthn\PublicKeyCredentialCreationOptions;
1313
use Webauthn\PublicKeyCredentialDescriptor;
1414
use Webauthn\Tests\MemoryPublicKeyCredentialSourceRepository;
@@ -23,8 +23,8 @@ final class AttestationTest extends AbstractTestCase
2323
*/
2424
public function aResponseCannotBeLoaded(): void
2525
{
26-
static::expectException(RangeException::class);
27-
static::expectExceptionMessage('Incorrect padding');
26+
static::expectException(InvalidDataException::class);
27+
static::expectExceptionMessage('Unable to load the data');
2828
$response = '{"id":"wHU13DaUWRqIQq94SAfCG8jqUZGdW0N95hnchI3rG7s===","rawId":"wHU13DaUWRqIQq94SAfCG8jqUZGdW0N95hnchI3rG7s","response":{"authenticatorData":"lgTqgoJOmKStoUtEYtDXOo7EaRMNqRsZMHRZIp90o1kBAAAAag","signature":"MEYCIQD4faYQG08_xpmAxFwp33OObSPavG7iUCJimHhH2QwyVAIhAMVRovz5DR_itNGYzTpKgO2urLgx5F2mZf3U4INTRR74","userHandle":"MDFHN0VEWUMxQ1QxSjBUUVBIWEY3QVlGNUs","clientDataJSON":"eyJvcmlnaW4iOiJodHRwczovL3dlYmF1dGhuLnNwb21reS1sYWJzLmNvbSIsImNoYWxsZW5nZSI6IkhaaktrWURKTEgtVnF6bFgtaXpCcUc3Q1pvN0FVRmtobG12TnRHM1VKSjQiLCJ0eXBlIjoid2ViYXV0aG4uZ2V0In0"},"getClientExtensionResults":{},"type":"public-key"}';
2929
$this->getPublicKeyCredentialLoader()
3030
->load($response);

0 commit comments

Comments
 (0)