Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
TypeScript aiai-agentsai-crawlerai-scrapingai-searchcrawlerdata-extractionhtml-to-markdownllmmarkdownscraperscrapingweb-crawlerweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
fix(api): accept World ID's advertised Orb acr values (#5678)
Erik Engervall32fa6f6273da
diff --git a/apps/api/src/lib/__tests__/world-id.test.ts b/apps/api/src/lib/__tests__/world-id.test.tsindex 417d44967..f413ba793 100644--- a/apps/api/src/lib/__tests__/world-id.test.ts+++ b/apps/api/src/lib/__tests__/world-id.test.ts@@ -22,7 +22,7 @@ import {const ISSUER = "https://issuer.test";const CLIENT_ID = "app_test";-const ORB_ACR = "https://world.org/oidc/acr/orb-v3";+const ORB_ACR = "https://world.org/oidc/acr/orb";let privateKey: CryptoKey;let publicJwk: JWK;@@ -230,6 +230,25 @@ describe("device flow", () => {);});+ it("mints a credential for an Orb face-authenticated ID token", async () => {+ stubIssuer({+ status: 200,+ body: {+ id_token: await idToken({+ auth_time: 1,+ acr: "https://world.org/oidc/acr/orb-face",+ }),+ },+ });+ const result = await pollWorldIdDeviceFlow(sealDeviceCode("device-secret"));++ expect(result.outcome).toBe("approved");+ if (result.outcome !== "approved") throw new Error("expected approval");+ expect(verifyWorldIdCredential(result.credential)).toBe(+ worldIdSubjectHash(ISSUER, "human-1"),+ );+ });+it("refuses an ID token without the Orb authentication class", async () => {stubIssuer({status: 200,diff --git a/apps/api/src/lib/world-id.ts b/apps/api/src/lib/world-id.tsindex 292735236..b03620a20 100644--- a/apps/api/src/lib/world-id.ts+++ b/apps/api/src/lib/world-id.ts@@ -23,7 +23,11 @@ const MAX_CREDENTIAL_LENGTH = 512;const MAX_FUTURE_IAT_SECONDS = 30;const MAX_DEVICE_HANDLE_LENGTH = 2_048;const SUBJECT_HASH_PATTERN = /^[A-Za-z0-9_-]{43}$/;-const ORB_ACR = "https://world.org/oidc/acr/orb-v3";+// The issuer's advertised `acr_values_supported`: both mean an Orb-verified human.+const ORB_ACRS = new Set([+ "https://world.org/oidc/acr/orb",+ "https://world.org/oidc/acr/orb-face",+]);const DEVICE_CODE_GRANT = "urn:ietf:params:oauth:grant-type:device_code";const REQUEST_TIMEOUT_MS = 10_000;@@ -304,9 +308,7 @@ const TOKEN_REJECTIONS = [* Validates a World ID ID token and returns its subject hash, or null when the* token is rejected. Throws when the issuer's keys can't be fetched.*/-async function verifyWorldIdIdToken(- idToken: string,-): Promise<string | null> {+async function verifyWorldIdIdToken(idToken: string): Promise<string | null> {try {const { payload } = await jwtVerify(idToken, issuerJwks(), {issuer: issuer(),@@ -314,7 +316,11 @@ async function verifyWorldIdIdToken(algorithms: ["RS256"],requiredClaims: ["sub", "exp", "auth_time"],});- if (payload.acr !== ORB_ACR || typeof payload.sub !== "string") {+ if (+ typeof payload.acr !== "string" ||+ !ORB_ACRS.has(payload.acr) ||+ typeof payload.sub !== "string"+ ) {return null;}return worldIdSubjectHash(issuer(), payload.sub);