Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature to hide existing credentials #617

Merged
merged 1 commit into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,11 @@ parameters:
count: 1
path: src/symfony/src/Controller/AttestationControllerFactory.php

-
message: "#^Method Webauthn\\\\Bundle\\\\CredentialOptionsBuilder\\\\PublicKeyCredentialCreationOptionsBuilder\\:\\:getFromRequest\\(\\) invoked with 3 parameters, 2 required\\.$#"
count: 1
path: src/symfony/src/Controller/AttestationRequestController.php

-
message: "#^Call to an undefined method Symfony\\\\Component\\\\HttpFoundation\\\\Request\\:\\:getContentType\\(\\)\\.$#"
count: 1
Expand Down Expand Up @@ -807,11 +812,6 @@ parameters:
count: 1
path: src/symfony/src/CredentialOptionsBuilder/ProfileBasedRequestOptionsBuilder.php

-
message: "#^Should not use function \"dump\", please change the code\\.$#"
count: 1
path: src/symfony/src/CredentialOptionsBuilder/ProfileBasedRequestOptionsBuilder.php

-
message: """
#^Fetching class constant class of deprecated class Webauthn\\\\Bundle\\\\Event\\\\AuthenticatorAssertionResponseValidationFailedEvent\\:
Expand Down Expand Up @@ -1061,6 +1061,11 @@ parameters:
count: 4
path: src/symfony/src/DependencyInjection/WebauthnExtension.php

-
message: "#^Cannot access offset 'hide_existing…' on mixed\\.$#"
count: 1
path: src/symfony/src/DependencyInjection/WebauthnExtension.php

-
message: "#^Cannot access offset 'host' on mixed\\.$#"
count: 4
Expand Down
4 changes: 3 additions & 1 deletion src/symfony/src/Controller/AttestationControllerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@ public function createRequestController(
OptionsStorage $optionStorage,
CreationOptionsHandler $creationOptionsHandler,
FailureHandler|AuthenticationFailureHandlerInterface $failureHandler,
bool $hideExistingExcludedCredentials = false
): AttestationRequestController {
return new AttestationRequestController(
$optionsBuilder,
$userEntityGuesser,
$optionStorage,
$creationOptionsHandler,
$failureHandler
$failureHandler,
$hideExistingExcludedCredentials
);
}

Expand Down
7 changes: 6 additions & 1 deletion src/symfony/src/Controller/AttestationRequestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@ public function __construct(
private readonly OptionsStorage $optionsStorage,
private readonly CreationOptionsHandler $creationOptionsHandler,
private readonly FailureHandler|AuthenticationFailureHandlerInterface $failureHandler,
private readonly bool $hideExistingExcludedCredentials = false,
) {
}

public function __invoke(Request $request): Response
{
try {
$userEntity = $this->userEntityGuesser->findUserEntity($request);
$publicKeyCredentialCreationOptions = $this->extractor->getFromRequest($request, $userEntity);
$publicKeyCredentialCreationOptions = $this->extractor->getFromRequest(
$request,
$userEntity,
$this->hideExistingExcludedCredentials
);

$response = $this->creationOptionsHandler->onCreationOptions(
$publicKeyCredentialCreationOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public function __construct(

public function getFromRequest(
Request $request,
PublicKeyCredentialUserEntity $userEntity
PublicKeyCredentialUserEntity $userEntity,
bool $hideExistingExcludedCredentials = false
): PublicKeyCredentialCreationOptions {
$format = method_exists(
$request,
Expand All @@ -57,7 +58,7 @@ public function getFromRequest(
$format === 'json' || throw new BadRequestHttpException('Only JSON content type allowed');
$content = $request->getContent();

$excludedCredentials = $this->getCredentials($userEntity);
$excludedCredentials = $hideExistingExcludedCredentials === true ? [] : $this->getCredentials($userEntity);
$optionsRequest = $this->getServerPublicKeyCredentialCreationOptionsRequest($content);
$authenticatorSelectionData = $optionsRequest->authenticatorSelection;
$authenticatorSelection = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface PublicKeyCredentialCreationOptionsBuilder
{
public function getFromRequest(
Request $request,
PublicKeyCredentialUserEntity $userEntity
PublicKeyCredentialUserEntity $userEntity,
/*bool $hideExistingExcludedCredentials = false*/
): PublicKeyCredentialCreationOptions;
}
6 changes: 6 additions & 0 deletions src/symfony/src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,12 @@ private function addControllersConfig(ArrayNodeDefinition $rootNode): void
->scalarNode('user_entity_guesser')
->isRequired()
->end()
->scalarNode('hide_existing_credentials')
->info(
'In order to prevent username enumeration, the existing credentials can be hidden. This is highly recommended when the attestation ceremony is performed by anonymous users.'
)
->defaultFalse()
->end()
->scalarNode('options_storage')
->defaultValue(SessionStorage::class)
->info('Service responsible of the options/user entity storage during the ceremony')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ private function createAttestationRequestControllerAndRoute(
new Reference($optionsStorageId),
new Reference($optionsHandlerId),
new Reference($failureHandlerId),
true,
]);
$this->createControllerAndRoute(
$container,
Expand Down
1 change: 1 addition & 0 deletions src/symfony/src/DependencyInjection/WebauthnExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ private function loadCreationControllersSupport(ContainerBuilder $container, arr
new Reference($creationConfig['options_storage']),
new Reference($creationConfig['options_handler']),
new Reference($creationConfig['failure_handler']),
$creationConfig['hide_existing_credentials'] ?? false,
])
->addTag(DynamicRouteCompilerPass::TAG, [
'method' => $creationConfig['options_method'],
Expand Down
1 change: 1 addition & 0 deletions tests/symfony/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ webauthn:
enabled: true
creation:
test:
hide_existing_credentials: true
options_path: '/devices/add/options'
result_path: '/devices/add'
#host: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function anExistingUserCanAskForOptionsUsingTheDedicatedController(): voi
static::assertArrayHasKey($expectedKey, $data);
}
static::assertSame('ok', $data['status']);
static::assertArrayNotHasKey('excludeCredentials', $data); // username enumeration prevention is enabled
}

#[Test]
Expand Down
18 changes: 18 additions & 0 deletions tests/symfony/functional/PublicKeyCredentialSourceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ public function __construct(
100
);
$this->saveCredentialSource($publicKeyCredentialSource1);
$publicKeyCredentialSource2 = PublicKeyCredentialSource::create(
base64_decode(
'Ac8zKrpVWv9UCwxY1FyMqkESz2lV4CNwTk2+Hp19LgKbvh5uQ2/i6AMbTbTz1zcNapCEeiLJPlAAVM4L7AIow6I=',
true
),
PublicKeyCredentialDescriptor::CREDENTIAL_TYPE_PUBLIC_KEY,
[],
AttestationStatement::TYPE_NONE,
EmptyTrustPath::create(),
Uuid::fromBinary(base64_decode('AAAAAAAAAAAAAAAAAAAAAA==', true)),
base64_decode(
'pQECAyYgASFYIJV56vRrFusoDf9hm3iDmllcxxXzzKyO9WruKw4kWx7zIlgg/nq63l8IMJcIdKDJcXRh9hoz0L+nVwP1Oxil3/oNQYs=',
true
),
'929fba2f-2361-4bc6-a917-bb76aa14c7f9',
100
);
$this->saveCredentialSource($publicKeyCredentialSource2);
}

public function findOneByCredentialId(string $publicKeyCredentialId): ?PublicKeyCredentialSource
Expand Down