feat(desktop): passkeys in the in-app browser on macOS (#16952)

Co-authored-by: Ben Davis <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-10-09 12:25:26 -07:00
1 parent 0a4d789128
commit 454b94a13a
24 files changed
+1762 -4

No files matched your search

+90 -1
View File
@@ -44,6 +44,7 @@ import {
preflightMacDesktopBuild,
preflightWindowsDesktopBuild,
renderMacPasskeyEntitlements,
resolveMacWebAuthnEntitlements,
resolveClerkPasskeyNativeArtifacts,
resolveMacPasskeySigningConfiguration,
resolveDesktopRuntimeDependencies,
@@ -95,6 +96,12 @@ import { BRAND_ASSET_PATHS } from "./lib/brand-assets.ts";
import { HostProcessArchitecture, HostProcessPlatform } from "@t3tools/shared/hostProcess";
import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
// Keeps pnpm from auto-installing TypeScript, a types-only peer, into the app.
const stagePackageExtensions = {
"electron-webauthn": { peerDependenciesMeta: { typescript: { optional: true } } },
"@electron-webauthn/macos": { peerDependenciesMeta: { typescript: { optional: true } } },
};
// A minimal stand-in for the Linux CLI release archive: one top-level
// directory named after the archive stem holding the executable, the web
// client, and the runtime externals with node-pty built from source.
@@ -454,6 +461,7 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
os: ["darwin"],
cpu: ["x64"],
},
packageExtensions: stagePackageExtensions,
});
assert.deepStrictEqual(createStageWorkspaceConfig({ platform: "linux", arch: "x64" }), {
supportedArchitectures: {
@@ -461,6 +469,7 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
cpu: ["x64"],
libc: ["glibc"],
},
packageExtensions: stagePackageExtensions,
});
// Windows stages only win32 natives; WSL runs the separately built Linux
// CLI archive rather than anything installed here.
@@ -469,18 +478,21 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
os: ["win32"],
cpu: ["x64"],
},
packageExtensions: stagePackageExtensions,
});
assert.deepStrictEqual(createStageWorkspaceConfig({ platform: "win", arch: "arm64" }), {
supportedArchitectures: {
os: ["win32"],
cpu: ["arm64"],
},
packageExtensions: stagePackageExtensions,
});
assert.deepStrictEqual(createStageWorkspaceConfig({ platform: "mac", arch: "universal" }), {
supportedArchitectures: {
os: ["darwin"],
cpu: ["arm64", "x64"],
},
packageExtensions: stagePackageExtensions,
});
});
@@ -507,6 +519,7 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
cpu: ["x64"],
libc: ["glibc"],
},
packageExtensions: stagePackageExtensions,
allowBuilds: {
electron: true,
"node-pty": true,
@@ -537,6 +550,7 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
os: ["darwin"],
cpu: ["arm64"],
},
packageExtensions: stagePackageExtensions,
},
);
});
@@ -1886,7 +1900,10 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
T3CODE_CLERK_PASSKEY_RP_DOMAINS:
" Clerk.Example.com,example.clerk.accounts.dev,clerk.example.com ",
});
const entitlements = renderMacPasskeyEntitlements(configuration);
const entitlements = renderMacPasskeyEntitlements(configuration, {
touchIdKeychainAccessGroup: undefined,
browserPasskeys: false,
});
assert.deepStrictEqual(configuration.rpDomains, [
"clerk.example.com",
@@ -1896,6 +1913,78 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
assert.include(entitlements, "<string>webcredentials:clerk.example.com</string>");
assert.include(entitlements, "<string>webcredentials:example.clerk.accounts.dev</string>");
assert.include(entitlements, "<key>com.apple.security.cs.allow-jit</key>");
assert.notInclude(entitlements, "keychain-access-groups");
assert.notInclude(entitlements, "com.apple.developer.web-browser.public-key-credential");
});
it("grants in-app browser passkey entitlements only when the provisioning profile does", () => {
const configuration = { appId: "com.t3tools.t3code", teamId: "ABC1234567" };
// Profiles are CMS envelopes around a plain XML plist.
const profile = (entitlements: string, outside = "") =>
`0\x82\x1f\x9a\x06\t*\x86H<?xml version="1.0"?><plist version="1.0"><dict>${outside}<key>Entitlements</key><dict>${entitlements}</dict></dict></plist>\x00\x01`;
const teamWildcardGroups = `<key>keychain-access-groups</key>
<array>
<string>ABC1234567.*</string>
<string>com.apple.token</string>
</array>`;
assert.deepStrictEqual(resolveMacWebAuthnEntitlements(profile(""), configuration), {
touchIdKeychainAccessGroup: undefined,
browserPasskeys: false,
});
assert.deepStrictEqual(
resolveMacWebAuthnEntitlements(
profile("<key>keychain-access-groups</key><array><string>OTHERTEAM1.*</string></array>"),
configuration,
),
{ touchIdKeychainAccessGroup: undefined, browserPasskeys: false },
);
// Only real values inside the Entitlements dict count: not comments, not
// explicit false, not keys elsewhere in the profile.
assert.deepStrictEqual(
resolveMacWebAuthnEntitlements(
profile(
`<!-- ${teamWildcardGroups}
<key>com.apple.developer.web-browser.public-key-credential</key><true/> -->
<key>com.apple.developer.web-browser.public-key-credential</key><false/>`,
teamWildcardGroups,
),
configuration,
),
{ touchIdKeychainAccessGroup: undefined, browserPasskeys: false },
);
assert.deepStrictEqual(
resolveMacWebAuthnEntitlements(
profile(
`${teamWildcardGroups}
<key>com.apple.developer.web-browser.public-key-credential</key>
<true/>`,
),
configuration,
),
{
touchIdKeychainAccessGroup: "ABC1234567.com.t3tools.t3code.webauthn",
browserPasskeys: true,
},
);
const entitlements = renderMacPasskeyEntitlements(
{ ...configuration, rpDomains: ["clerk.example.com"], provisioningProfilePath: "" },
resolveMacWebAuthnEntitlements(
profile(
`${teamWildcardGroups}<key>com.apple.developer.web-browser.public-key-credential</key><true/>`,
),
configuration,
),
);
assert.match(
entitlements,
/<key>keychain-access-groups<\/key>\s*<array>\s*<string>ABC1234567\.com\.t3tools\.t3code\.webauthn<\/string>\s*<\/array>/u,
);
assert.match(
entitlements,
/<key>com\.apple\.developer\.web-browser\.public-key-credential<\/key>\s*<true\/>/u,
);
});
it("rejects incomplete macOS passkey signing configuration", () => {
+105 -2
View File
@@ -4,6 +4,8 @@
import * as NodeFSP from "node:fs/promises";
import * as NodeCrypto from "node:crypto";
import * as NodeModule from "node:module";
// plist is CommonJS; Node cannot load its named exports from an ES module.
import Plist from "plist";
import {
createPackageWithOptions,
@@ -80,10 +82,28 @@ const StageWorkspaceConfig = Schema.Struct({
allowBuilds: Schema.optional(Schema.Record(Schema.String, Schema.Boolean)),
patchedDependencies: Schema.optional(Schema.Record(Schema.String, Schema.String)),
overrides: Schema.optional(Schema.Record(Schema.String, Schema.String)),
packageExtensions: Schema.optional(
Schema.Record(
Schema.String,
Schema.Struct({
peerDependenciesMeta: Schema.Record(
Schema.String,
Schema.Struct({ optional: Schema.Boolean }),
),
}),
),
),
nodeLinker: Schema.optional(Schema.Literals(["hoisted"])),
});
type StageWorkspaceConfig = typeof StageWorkspaceConfig.Type;
// electron-webauthn declares TypeScript as a peer only for its typings. pnpm
// auto-installs missing peers, which would ship a compiler inside the app.
const STAGE_PACKAGE_EXTENSIONS = {
"electron-webauthn": { peerDependenciesMeta: { typescript: { optional: true } } },
"@electron-webauthn/macos": { peerDependenciesMeta: { typescript: { optional: true } } },
} as const;
const RepoRoot = Effect.service(Path.Path).pipe(
Effect.flatMap((path) => path.fromFileUrl(new URL("..", import.meta.url))),
);
@@ -926,6 +946,7 @@ interface StagePackageJson {
readonly version: string;
readonly buildVersion: string;
readonly t3codeCommitHash: string;
readonly t3codeWebAuthn?: MacWebAuthnEntitlements;
readonly private: true;
readonly packageManager: string;
readonly description: string;
@@ -1289,12 +1310,80 @@ function escapeXml(value: string): string {
.replaceAll("'", "&apos;");
}
/**
* Passkey entitlements for the in-app browser. Each is granted only when the
* provisioning profile authorizes it: macOS refuses to launch an app that
* claims a restricted entitlement its embedded profile does not carry.
*/
export interface MacWebAuthnEntitlements {
/** Keychain group for Electron's Touch ID passkeys. */
readonly touchIdKeychainAccessGroup: string | undefined;
/** Apple's managed browser entitlement, which allows passkeys for any site. */
readonly browserPasskeys: boolean;
}
const BROWSER_PASSKEYS_ENTITLEMENT = "com.apple.developer.web-browser.public-key-credential";
const ProvisioningProfilePlist = Schema.Struct({
Entitlements: Schema.Struct({
"keychain-access-groups": Schema.optional(Schema.Array(Schema.String)),
[BROWSER_PASSKEYS_ENTITLEMENT]: Schema.optional(Schema.Boolean),
}),
});
const isProvisioningProfilePlist = Schema.is(ProvisioningProfilePlist);
/**
* Reads the Entitlements dict of the XML plist a provisioning profile wraps in
* its CMS envelope. Anything unreadable grants nothing.
*/
const readProfileEntitlements = (provisioningProfile: string) => {
const start = provisioningProfile.indexOf("<?xml");
const end = provisioningProfile.indexOf("</plist>", start);
if (start === -1 || end === -1) return undefined;
try {
const profile: unknown = Plist.parse(provisioningProfile.slice(start, end + "</plist>".length));
return isProvisioningProfilePlist(profile) ? profile.Entitlements : undefined;
} catch {
return undefined;
}
};
export function resolveMacWebAuthnEntitlements(
provisioningProfile: string,
configuration: Pick<MacPasskeySigningConfiguration, "appId" | "teamId">,
): MacWebAuthnEntitlements {
const entitlements = readProfileEntitlements(provisioningProfile);
const keychainAccessGroup = `${configuration.teamId}.${configuration.appId}.webauthn`;
const keychainGroupAuthorized = (entitlements?.["keychain-access-groups"] ?? []).some((group) =>
group.endsWith("*")
? keychainAccessGroup.startsWith(group.slice(0, -1))
: group === keychainAccessGroup,
);
return {
touchIdKeychainAccessGroup: keychainGroupAuthorized ? keychainAccessGroup : undefined,
browserPasskeys: entitlements?.[BROWSER_PASSKEYS_ENTITLEMENT] === true,
};
}
export function renderMacPasskeyEntitlements(
configuration: MacPasskeySigningConfiguration,
webAuthn: MacWebAuthnEntitlements,
): string {
const associatedDomains = configuration.rpDomains
.map((domain) => ` <string>webcredentials:${escapeXml(domain)}</string>`)
.join("\n");
const keychainAccessGroups = webAuthn.touchIdKeychainAccessGroup
? `
<key>keychain-access-groups</key>
<array>
<string>${escapeXml(webAuthn.touchIdKeychainAccessGroup)}</string>
</array>`
: "";
const browserPasskeys = webAuthn.browserPasskeys
? `
<key>${BROWSER_PASSKEYS_ENTITLEMENT}</key>
<true/>`
: "";
return `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
@@ -1307,7 +1396,7 @@ export function renderMacPasskeyEntitlements(
<key>com.apple.developer.associated-domains</key>
<array>
${associatedDomains}
</array>
</array>${keychainAccessGroups}${browserPasskeys}
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
@@ -1535,6 +1624,7 @@ export function createStageWorkspaceConfig(input: {
? { patchedDependencies }
: {}),
...(overrides && Object.keys(overrides).length > 0 ? { overrides } : {}),
packageExtensions: STAGE_PACKAGE_EXTENSIONS,
};
}
@@ -3673,13 +3763,24 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
const macEntitlementsPath = macPasskeySigning
? path.join(stageAppDir, "entitlements.mac.plist")
: undefined;
let macWebAuthn: MacWebAuthnEntitlements | undefined;
if (macPasskeySigning && macEntitlementsPath) {
if (!(yield* fs.exists(macPasskeySigning.provisioningProfilePath))) {
return yield* new MacProvisioningProfileNotFoundError({
provisioningProfilePath: macPasskeySigning.provisioningProfilePath,
});
}
yield* fs.writeFileString(macEntitlementsPath, renderMacPasskeyEntitlements(macPasskeySigning));
macWebAuthn = resolveMacWebAuthnEntitlements(
yield* fs.readFileString(macPasskeySigning.provisioningProfilePath),
macPasskeySigning,
);
yield* Effect.log(
`[desktop-artifact] In-app browser passkeys: Touch ID ${macWebAuthn.touchIdKeychainAccessGroup ? "enabled" : "disabled"}, browser passkeys ${macWebAuthn.browserPasskeys ? "enabled" : "disabled"}.`,
);
yield* fs.writeFileString(
macEntitlementsPath,
renderMacPasskeyEntitlements(macPasskeySigning, macWebAuthn),
);
}
// Windows splits dependencies per process: app.asar carries only the
@@ -3709,6 +3810,8 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
version: appVersion,
buildVersion: appVersion,
t3codeCommitHash: commitHash,
// Read by apps/desktop/src/preview/Passkeys.ts; must match the signed entitlements.
...(macWebAuthn ? { t3codeWebAuthn: macWebAuthn } : {}),
private: true,
packageManager: rootPackageJson.packageManager,
description:
+1
View File
@@ -16,6 +16,7 @@ export const DESKTOP_RUNTIME_EXTERNAL_PREFIXES = [
"@napi-rs/keyring",
"@crowecawcaw/xa11y",
"@clerk/electron-passkeys",
"electron-webauthn",
"ffi-rs",
"@yuuang/",
// Reads its own bundle from disk by resolving `playwright-core/package.json`
+2
View File
@@ -13,11 +13,13 @@
"@t3tools/shared": "workspace:*",
"@t3tools/tailscale": "workspace:*",
"effect": "catalog:",
"plist": "catalog:",
"pngjs": "7.0.0",
"sharp": "0.35.4"
},
"devDependencies": {
"@effect/vitest": "catalog:",
"@types/plist": "catalog:",
"@types/pngjs": "6.0.5",
"typescript": "catalog:",
"typescript-legacy": "npm:typescript@~6.0.3",