feat(desktop): passkeys in the in-app browser on macOS #16952
main fromrefs/pull/16952/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
juliusmarminge added labelsmacroscope-review
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/desktop/src/preview/Passkeys.ts lines 192 to 193OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +173,21 @@173+ data: {174+ ...result.data,175+ authData: authData ? Buffer.from(authData).toString("base64url") : "",176+ transports: [],177+ },178+ };179+ };180+181+const getCeremony =182+ (publicKey: PublicKeyCredentialRequestOptions, origin: string): Ceremony =>183+ async (webauthn, options) => {184+ // WebAuthn defaults the RP ID to the caller's host; the native layer requires it.185+ const result = await webauthn.getCredential(186+ { ...publicKey, rpId: publicKey.rpId ?? new URL(origin).hostname },187+ options,188+ );189+ return result.success ? result : { success: false, error: result.error };190+ };191+192+/** @public Service construction is part of the canonical Effect module API. */193+export const make = Effect.gen(function* () {
- apps/desktop/src/preview/Passkeys.ts lines 152 to 152OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +132,21 @@132+133+// Secure contexts only, as in Chromium: https, or http on this machine.134+const isTrustworthyOrigin = (origin: string) => {135+ if (!URL.canParse(origin)) return false;136+ const { protocol, hostname } = new URL(origin);137+ return (138+ protocol === "https:" ||139+ (protocol === "http:" &&140+ (hostname === "localhost" ||141+ hostname.endsWith(".localhost") ||142+ hostname === "127.0.0.1" ||143+ hostname === "[::1]"))144+ );145+};146+147+const createCeremony =148+ (publicKey: PublicKeyCredentialCreationOptions): Ceremony =>149+ async (webauthn, options) => {150+ // The native layer only converts P-256 keys and never settles for any151+ // other algorithm, so ES256 is the only one it may negotiate.152+ const params: unknown = publicKey.pubKeyCredParams;
- apps/desktop/src/preview/Passkeys.ts line 185OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +165,21 @@165+ if (!result.success) return { success: false, error: result.error };166+ // The native layer reports parsed authenticator data as JSON and claims167+ // every credential is a synced platform passkey; neither is reliable.168+ const authData = authenticatorDataFromAttestation(169+ Buffer.from(result.data.attestationObject, "base64url"),170+ );171+ return {172+ success: true,173+ data: {174+ ...result.data,175+ authData: authData ? Buffer.from(authData).toString("base64url") : "",176+ transports: [],177+ },178+ };179+ };180+181+const getCeremony =182+ (publicKey: PublicKeyCredentialRequestOptions, origin: string): Ceremony =>183+ async (webauthn, options) => {184+ // WebAuthn defaults the RP ID to the caller's host; the native layer requires it.185+ const result = await webauthn.getCredential(apps/desktop/src/preview/Passkeys.ts line 262OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +242,21 @@242+ // be trusted for the origin. Read the committed origin before any await:243+ // the frame object outlives a navigation.244+ const origin = frame.origin;245+ // Like Chromium, only a focused page may open the sheet, one at a time.246+ if (!isTrustworthyOrigin(origin) || ceremonyPending || !guest.isFocused()) {247+ return notAllowed;248+ }249+ if (typeof publicKey !== "object" || publicKey === null) {250+ return { success: false, error: "TypeError" };251+ }252+ const host = guest.hostWebContents253+ ? BrowserWindow.fromWebContents(guest.hostWebContents)254+ : null;255+ if (!host || host.isDestroyed()) return notAllowed;256+257+ ceremonyPending = true;258+ try {259+ const webauthn = await import("electron-webauthn");260+ const result = await withDeadline(261+ ceremony(origin)(webauthn, {262+ currentOrigin: origin,
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/desktop/src/preview/PasskeyBackendMac.ts lines 63 to 70OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +50,21 @@50+ params.some(51+ (param: unknown) =>52+ typeof param === "object" && param !== null && "alg" in param && param.alg === ES256,53+ );54+ if (!allowsEs256) return { success: false, error: "NotSupportedError" };55+ const { webauthn, options } = await nativeOptions(context);56+ const result = await webauthn.createCredential(57+ { ...publicKey, pubKeyCredParams: [{ type: "public-key", alg: ES256 }] },58+ options,59+ );60+ if (!result.success) return { success: false, error: result.error };61+ // The native layer reports parsed authenticator data as JSON and claims62+ // every credential is a synced platform passkey; neither is reliable.63+ const authData = authenticatorDataFromAttestation(64+ Buffer.from(result.data.attestationObject, "base64url"),65+ );66+ return {67+ success: true,68+ data: {69+ ...result.data,70+ authData: authData ? Buffer.from(authData).toString("base64url") : "",
juliusmarminge merged this454b94a
juliusmarminge closed this
Sign in to join this conversation.
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline:
91a6646· PR result:9c3100a· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.