Skip to content

Open-source status page, incident response and uptime monitoring

fix: accept OAuth clients that can fall back to public auth (#2657)

Maximilian Kaskec540749b0b8b
diff --git a/packages/services/src/oauth/__tests__/cimd.test.ts b/packages/services/src/oauth/__tests__/cimd.test.ts
index 216ab7f3a..dd9960411 100644
--- a/packages/services/src/oauth/__tests__/cimd.test.ts
+++ b/packages/services/src/oauth/__tests__/cimd.test.ts
@@ -135,6 +135,38 @@ describe("parseClientMetadataDocument", () => {
expect(parsed.client_name).toBe("Partner App");
});
+ test("accepts a client that prefers private_key_jwt but also supports none", () => {
+ const parsed = parseClientMetadataDocument(
+ CLIENT_ID,
+ doc({
+ token_endpoint_auth_method: "private_key_jwt",
+ token_endpoint_auth_methods_supported: ["none", "private_key_jwt"],
+ }),
+ );
+ expect(parsed.client_name).toBe("Partner App");
+ });
+
+ test("rejects a confidential client that cannot fall back to none", () => {
+ expect(() =>
+ parseClientMetadataDocument(
+ CLIENT_ID,
+ doc({
+ token_endpoint_auth_method: "private_key_jwt",
+ token_endpoint_auth_methods_supported: ["private_key_jwt"],
+ }),
+ ),
+ ).toThrow(OAuthError);
+ });
+
+ test("a supported-methods list without none is rejected even if the method is omitted", () => {
+ expect(() =>
+ parseClientMetadataDocument(
+ CLIENT_ID,
+ doc({ token_endpoint_auth_methods_supported: ["private_key_jwt"] }),
+ ),
+ ).toThrow(OAuthError);
+ });
+
test("rejects a document whose client_id differs from its URL", () => {
expect(() =>
parseClientMetadataDocument(
diff --git a/packages/services/src/oauth/cimd.ts b/packages/services/src/oauth/cimd.ts
index a0966401b..0adfd635c 100644
--- a/packages/services/src/oauth/cimd.ts
+++ b/packages/services/src/oauth/cimd.ts
@@ -79,12 +79,27 @@ const redirectUriSchema = z.string().refine((value) => {
}
}, "redirect_uris must be https or loopback, without fragment or credentials");
-export const ClientMetadataDocument = z.object({
- client_id: z.string().url(),
- client_name: z.string().trim().min(1).max(120).optional(),
- redirect_uris: z.array(redirectUriSchema).min(1).max(20),
- token_endpoint_auth_method: z.literal("none").optional(),
-});
+export const ClientMetadataDocument = z
+ .object({
+ client_id: z.string().url(),
+ client_name: z.string().trim().min(1).max(120).optional(),
+ redirect_uris: z.array(redirectUriSchema).min(1).max(20),
+ token_endpoint_auth_method: z.string().optional(),
+ // Non-standard but published by e.g. ChatGPT: the client prefers
+ // private_key_jwt yet can fall back to `none` when the server only offers that.
+ token_endpoint_auth_methods_supported: z.array(z.string()).optional(),
+ })
+ .refine(
+ (doc) =>
+ doc.token_endpoint_auth_methods_supported
+ ? doc.token_endpoint_auth_methods_supported.includes("none")
+ : (doc.token_endpoint_auth_method ?? "none") === "none",
+ {
+ path: ["token_endpoint_auth_method"],
+ message:
+ 'Only public clients are supported: expected "none", or "none" listed in token_endpoint_auth_methods_supported',
+ },
+ );
export type ClientMetadataDocument = z.infer<typeof ClientMetadataDocument>;
/** Validates the body and pins `client_id` to the URL it was fetched from. */