mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-25 14:17:31 +00:00
fix(auth): move passkeys to SimpleWebAuthn 14, which no longer fetches a CRL a client names
@simplewebauthn/server 13.3.3 fetched the CRL address in an android-key attestation certificate before it checked the chain or the signature, with no timeout or size cap, so anyone signed in could make the server request any URL by registering a passkey. 14.1.0 only checks revocation for a chain it validated against Google's pinned roots. 14.x refuses an expected origin with a path, a trailing slash or an uppercase host and an RP ID that is not lower case, where 13.x only failed to match them. The configured origins are now reduced to the origin the browser reports and the RP ID is lower-cased, so such settings keep working; an origins list in which nothing parses leaves passkeys unconfigured instead of falling back to APP_URL. Verification gets the algorithm list the options offer, and stored transports are read as plain strings. Stored credentials keep their format. typescript-eslint moves to 8.73.0.
This commit is contained in:
@@ -329,6 +329,7 @@ describe('passkeyRegisterOptions', () => {
|
||||
const { user, password } = createUser(testDb);
|
||||
await insertCredential(user.id, { credential_id: 'cred-a', transports: JSON.stringify(['usb', 'nfc']) });
|
||||
await insertCredential(user.id, { credential_id: 'cred-b', transports: 'not-json' });
|
||||
await insertCredential(user.id, { credential_id: 'cred-c', transports: JSON.stringify(['usb', 7, null]) });
|
||||
await seedChallenge('stale', user.id, 'registration', Date.now() - 1000); // purged on the way in
|
||||
swMock.generateRegistrationOptions.mockResolvedValue({ challenge: 'reg-chal' });
|
||||
|
||||
@@ -345,6 +346,7 @@ describe('passkeyRegisterOptions', () => {
|
||||
expect(call.excludeCredentials).toEqual([
|
||||
{ id: 'cred-a', transports: ['usb', 'nfc'] },
|
||||
{ id: 'cred-b', transports: undefined }, // unparseable transports degrade to undefined
|
||||
{ id: 'cred-c', transports: ['usb'] }, // only string entries are transports
|
||||
]);
|
||||
|
||||
const stored = await findRows(orm, WebauthnChallenges);
|
||||
@@ -505,6 +507,8 @@ describe('passkeyRegisterVerify', () => {
|
||||
aaguid: 'aaguid-1',
|
||||
});
|
||||
expect(Buffer.from(row?.public_key as Buffer)).toEqual(Buffer.from([9, 9, 9]));
|
||||
// Verification accepts exactly the algorithms the options offered.
|
||||
expect(swMock.verifyRegistrationResponse.mock.calls[0][0].supportedAlgorithmIDs).toEqual([-8, -7, -257]);
|
||||
});
|
||||
|
||||
it('PASSKEY-SVC-012: defaults a blank name by device type and caps a long one at 60 chars', async () => {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { AppSettingsRepository } from '../../../src/db/repositories/AppSettings.repository';
|
||||
import { WebauthnConfigService, originWithinRpScope } from '../../../src/nest/auth/webauthn-config.service';
|
||||
import { Logger } from '@nestjs/common';
|
||||
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
||||
|
||||
@@ -129,6 +130,56 @@ describe('WebauthnConfigService.resolve', () => {
|
||||
vi.stubEnv('WEBAUTHN_ORIGINS', 'https://env.example.org');
|
||||
expect((await svc.resolve())!.explicitOrigins).toBe(true);
|
||||
});
|
||||
|
||||
// The verifier refuses an expected origin with a path, a trailing slash or an
|
||||
// uppercase host, and an RP ID that is not lower case. Each is reduced to the
|
||||
// form the browser reports, so a value that worked before keeps working.
|
||||
it('WAC-014: configured origins are reduced to scheme, host and port, deduplicated', async () => {
|
||||
settingsStore.set('webauthn_rp_id', 'example.org');
|
||||
settingsStore.set(
|
||||
'webauthn_origins',
|
||||
'https://A.Example.org/trek/, https://a.example.org, https://b.example.org:8443/x//, http://localhost:5173/',
|
||||
);
|
||||
expect(await svc.resolve()).toMatchObject({
|
||||
origins: ['https://a.example.org', 'https://b.example.org:8443', 'http://localhost:5173'],
|
||||
explicitOrigins: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('WAC-015: the RP ID is lower-cased, from the setting and from the env var', async () => {
|
||||
settingsStore.set('webauthn_rp_id', ' Trek.Example.ORG ');
|
||||
expect(await svc.resolve()).toMatchObject({ rpID: 'trek.example.org' });
|
||||
|
||||
vi.stubEnv('WEBAUTHN_RP_ID', 'ENV.example.org');
|
||||
expect(await svc.resolve()).toMatchObject({ rpID: 'env.example.org' });
|
||||
});
|
||||
|
||||
it('WAC-016: an APP_URL with a path, a trailing slash or an uppercase host derives its origin', async () => {
|
||||
appUrlRef.value = 'https://Trek.Example.org/app/';
|
||||
expect(await svc.resolve()).toMatchObject({
|
||||
rpID: 'trek.example.org',
|
||||
origins: ['https://trek.example.org'],
|
||||
explicitOrigins: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('WAC-017: an origin that does not parse is dropped and named in a warning; other schemes are kept', async () => {
|
||||
const warn = vi.spyOn(Logger.prototype, 'warn').mockImplementation(() => undefined);
|
||||
settingsStore.set('webauthn_rp_id', 'example.org');
|
||||
settingsStore.set('webauthn_origins', 'example.org, https://example.org, android:apk-key-hash:abc123');
|
||||
expect(await svc.resolve()).toMatchObject({ origins: ['https://example.org', 'android:apk-key-hash:abc123'] });
|
||||
expect(warn).toHaveBeenCalledWith('Ignoring passkey origins that are not valid URLs: example.org');
|
||||
warn.mockRestore();
|
||||
});
|
||||
|
||||
it('WAC-018: an explicit list with no parseable origin leaves passkeys unconfigured instead of falling back', async () => {
|
||||
const warn = vi.spyOn(Logger.prototype, 'warn').mockImplementation(() => undefined);
|
||||
appUrlRef.value = 'https://trek.example.org';
|
||||
settingsStore.set('webauthn_origins', 'trek.example.org');
|
||||
expect(await svc.resolve()).toBeNull();
|
||||
expect(warn).toHaveBeenCalledTimes(1);
|
||||
warn.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
// The scope rule mirrors what the browser enforces for a ceremony: https-only
|
||||
|
||||
Reference in New Issue
Block a user