🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(oidc): drop key_ops from JWKS for oidc-provider 9.14 (#22964)
YuTengjing1691396085d4
diff --git a/src/libs/oidc-provider/jwt.ts b/src/libs/oidc-provider/jwt.tsindex 7b85108b8f4..61d4c7966fc 100644--- a/src/libs/oidc-provider/jwt.ts+++ b/src/libs/oidc-provider/jwt.ts@@ -69,7 +69,14 @@ export const getJWKS = (): object => {throw new Error('No RSA key with RS256 algorithm found in JWKS');}- return jwks;+ // oidc-provider 9.14+ rejects any `key_ops` member ("jwks.keys[0].key_ops is not+ // supported"), but keys exported through Web Crypto carry `key_ops: ['sign']`.+ // The provider only signs with these keys, so dropping the member keeps existing+ // JWKS_KEY values working without asking deployments to regenerate them.+ return {+ ...jwks,+ keys: jwks.keys.map(({ key_ops: _keyOps, ...key }: Record<string, unknown>) => key),+ };} catch (error) {console.error('Failed to parse JWKS:', error);throw new Error(`JWKS_KEY parse error: ${(error as Error).message}`, { cause: error });diff --git a/src/libs/oidc-provider/provider.native-client.test.ts b/src/libs/oidc-provider/provider.native-client.test.tsindex 58f289ace34..fcfe92276c9 100644--- a/src/libs/oidc-provider/provider.native-client.test.ts+++ b/src/libs/oidc-provider/provider.native-client.test.ts@@ -6,7 +6,7 @@* HTTP: discovery, a code + PKCE sign-in, and sign-out through the advertised* revocation endpoint.*/-import { createHash, generateKeyPairSync, randomBytes } from 'node:crypto';+import { createHash, randomBytes } from 'node:crypto';import { createServer, type Server } from 'node:http';import type { AddressInfo } from 'node:net';@@ -135,9 +135,22 @@ const signIn = async () => {};beforeAll(async () => {- const { privateKey } = generateKeyPairSync('rsa', { modulusLength: 2048 });+ // Export through Web Crypto like the dev runtime and many self-hosted setups do: the+ // private JWK then carries `key_ops: ['sign']`, which oidc-provider 9.14+ rejects.+ const { privateKey } = await crypto.subtle.generateKey(+ {+ hash: 'SHA-256',+ modulusLength: 2048,+ name: 'RSASSA-PKCS1-v1_5',+ publicExponent: new Uint8Array([1, 0, 1]),+ },+ true,+ ['sign', 'verify'],+ );+ const privateJwk = await crypto.subtle.exportKey('jwk', privateKey);+ expect(privateJwk.key_ops).toEqual(['sign']);authEnvMock.JWKS_KEY = JSON.stringify({- keys: [{ ...privateKey.export({ format: 'jwk' }), alg: 'RS256', kid: 'test', use: 'sig' }],+ keys: [{ ...privateJwk, alg: 'RS256', kid: 'test', use: 'sig' }],});provider = await createOIDCProvider({} as any);server = createServer(provider.callback());@@ -149,6 +162,19 @@ afterAll(async () => {await new Promise<void>((resolve) => (server ? server.close(() => resolve()) : resolve()));});+describe('signing keys', () => {+ it('serves a JWKS_KEY exported with key_ops as its public signing key', async () => {+ const { jwks_uri } = await discovery();+ const response = await fetch(`${origin}${new URL(jwks_uri).pathname}`);++ expect(response.status).toBe(200);+ const { keys } = (await response.json()) as { keys: Record<string, unknown>[] };+ expect(keys).toEqual([expect.objectContaining({ alg: 'RS256', kid: 'test', use: 'sig' })]);+ expect(keys[0]).not.toHaveProperty('key_ops');+ expect(keys[0]).not.toHaveProperty('d');+ });+});+describe('native client endpoints', () => {// The provider is mounted under /oidc and receives the untouched pathname, so an// endpoint left at its default path (`/token/revocation`) is advertised where