Skip to content

Commit 2872910

Browse files
fix(desktop): a passkey with unreadable authenticator data fails instead of registering empty
Sites verify a new passkey from its authenticator data, so a credential without it cannot be used; the page now hears NotAllowedError at creation. Fake timers are also restored in afterEach, so a failing test cannot leak them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 979ad00 commit 2872910

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

‎apps/desktop/src/preview/PasskeyBackendMac.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,14 @@ export const macPasskeyBackend: PasskeyBackend = {
6363
const authData = authenticatorDataFromAttestation(
6464
Buffer.from(result.data.attestationObject, "base64url"),
6565
);
66+
// Sites verify the new credential from its authenticator data; without it
67+
// the passkey is unusable, so say so now rather than let sign-up fail later.
68+
if (!authData) return { success: false, error: "NotAllowedError" };
6669
return {
6770
success: true,
6871
data: {
6972
...result.data,
70-
authData: authData ? Buffer.from(authData).toString("base64url") : "",
73+
authData: Buffer.from(authData).toString("base64url"),
7174
transports: [],
7275
},
7376
};

‎apps/desktop/src/preview/Passkeys.test.ts‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as Effect from "effect/Effect";
33
import * as Fiber from "effect/Fiber";
44
import * as FileSystem from "effect/FileSystem";
55
import * as Layer from "effect/Layer";
6-
import { beforeEach, vi } from "vite-plus/test";
6+
import { afterEach, beforeEach, vi } from "vite-plus/test";
77

88
const electron = vi.hoisted(() => ({
99
configureWebAuthn: vi.fn(),
@@ -93,6 +93,10 @@ describe("PreviewPasskeys", () => {
9393
getNativeWindowHandle: () => Buffer.from([1]),
9494
});
9595
});
96+
// Restored here so a failing fake-timer test cannot leak fake timers into the next one.
97+
afterEach(() => {
98+
vi.useRealTimers();
99+
});
96100

97101
it.effect("pins each guest ceremony to the origin of the frame that asked", () =>
98102
Effect.gen(function* () {
@@ -185,6 +189,16 @@ describe("PreviewPasskeys", () => {
185189
});
186190
assert.deepStrictEqual(malformed, { success: false, error: "TypeError" });
187191
assert.strictEqual(webauthn.createCredential.mock.calls.length, 1);
192+
193+
// Without authenticator data the site cannot verify the passkey.
194+
webauthn.createCredential.mockResolvedValueOnce({
195+
success: true,
196+
data: { credentialId: "AQ", attestationObject: Buffer.from([0x00]).toString("base64url") },
197+
});
198+
assert.deepStrictEqual(yield* call(PASSKEY_CREATE_CHANNEL, publicKey), {
199+
success: false,
200+
error: "NotAllowedError",
201+
});
188202
}).pipe(Effect.provide(bridgeLayer)),
189203
);
190204

@@ -273,7 +287,6 @@ describe("PreviewPasskeys", () => {
273287
call(PASSKEY_GET_CHANNEL, { challenge: new Uint8Array([1]), timeout: 1_000 }),
274288
);
275289
yield* Effect.promise(() => vi.advanceTimersByTimeAsync(6_000));
276-
vi.useRealTimers();
277290

278291
assert.deepStrictEqual(yield* Fiber.join(pending), {
279292
success: false,

0 commit comments

Comments
 (0)