Debian Codegraph @

lib/3rdParty/composer/web-auth/webauthn-lib/src/CeremonyStep/CheckTopOrigin.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Webauthn\CeremonyStep;
6
7 use function trigger_deprecation;
8 use Webauthn\AuthenticatorAssertionResponse;
9 use Webauthn\AuthenticatorAttestationResponse;
10 use Webauthn\CredentialRecord;
11 use Webauthn\Exception\AuthenticatorResponseVerificationException;
12 use Webauthn\PublicKeyCredentialCreationOptions;
13 use Webauthn\PublicKeyCredentialRequestOptions;
14 use Webauthn\PublicKeyCredentialSource;
15
16 class CheckTopOrigin implements CeremonyStep
17 {
18 public function __construct(
19 private readonly null|TopOriginValidator $topOriginValidator = null
20 ) {
21 }
22
23 public function process(
24 CredentialRecord $credentialRecord,
25 AuthenticatorAssertionResponse|AuthenticatorAttestationResponse $authenticatorResponse,
26 PublicKeyCredentialRequestOptions|PublicKeyCredentialCreationOptions $publicKeyCredentialOptions,
27 ?string $userHandle,
28 string $host
29 ): void {
30 if ($credentialRecord instanceof PublicKeyCredentialSource) {
31 trigger_deprecation(
32 'web-auth/webauthn-lib',
33 '5.3',
34 'Passing a PublicKeyCredentialSource to "%s::process()" is deprecated, pass a CredentialRecord instead.',
35 self::class
36 );
37 }
38 $topOrigin = $authenticatorResponse->clientDataJSON->topOrigin;
39 if ($topOrigin === null) {
40 return;
41 }
42 if ($authenticatorResponse->clientDataJSON->crossOrigin !== true) {
43 throw AuthenticatorResponseVerificationException::create('The response is not cross-origin.');
44 }
45 if ($this->topOriginValidator === null) {
46 throw AuthenticatorResponseVerificationException::create(
47 'A cross-origin response was received but no TopOriginValidator is configured. '
48 . 'Configure one via CeremonyStepManagerFactory::enableTopOriginValidator() '
49 . 'to opt in to cross-origin (iframe) ceremonies.'
50 );
51 }
52 $this->topOriginValidator->validate($topOrigin);
53 }
54 }