🤯 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): pin provider request host to APP_URL (#21985)
Arvin Xu10b35ed3458c
diff --git a/src/libs/oidc-provider/http-adapter.test.ts b/src/libs/oidc-provider/http-adapter.test.tsindex e889221e655..31060bbfc5f 100644--- a/src/libs/oidc-provider/http-adapter.test.ts+++ b/src/libs/oidc-provider/http-adapter.test.ts@@ -70,6 +70,26 @@ describe('OIDC HTTP adapter', () => {}});+ it('pins the host to APP_URL even when a proxy forwards another domain', async () => {+ const request = new Request('https://lobehub-cloud-next-stable.vercel.app/oidc/device/auth', {+ headers: {+ 'host': 'lobehub-cloud-next-stable.vercel.app',+ 'x-forwarded-host': 'lobehub-cloud-next-stable.vercel.app',+ 'x-forwarded-proto': 'http',+ },+ method: 'POST',+ }) as unknown as NextRequest;++ const { createNodeRequest } = await import('./http-adapter');+ const nodeRequest = await createNodeRequest(request);++ expect(nodeRequest.headers).toMatchObject({+ 'host': 'example.com',+ 'x-forwarded-host': 'example.com',+ 'x-forwarded-proto': 'https',+ });+ });+it('passes POST bodies through as a readable Node stream without pre-parsing', async () => {const body = 'grant_type=authorization_code&code=test-code';const request = new Request('https://example.com/oidc/token?client_id=test', {diff --git a/src/libs/oidc-provider/http-adapter.ts b/src/libs/oidc-provider/http-adapter.tsindex a70706116ae..e7d13acca21 100644--- a/src/libs/oidc-provider/http-adapter.ts+++ b/src/libs/oidc-provider/http-adapter.ts@@ -24,6 +24,24 @@ export const convertHeadersToNodeHeaders = (nextHeaders: Headers): Record<stringreturn headers;};+/**+ * oidc-provider runs with `proxy = true` and builds every endpoint URL (device+ * verification, discovery endpoints, ...) from the forwarded host. Behind a+ * rewrite such as lobehub.com → the Vercel deployment, that host is the+ * deployment's own domain, so the CLI was told to open `*.vercel.app`. Pin the+ * host to APP_URL, the same origin the issuer is built from.+ */+const pinHostToAppUrl = (headers: Record<string, string>): Record<string, string> => {+ const appUrl = new URL(appEnv.APP_URL!);++ return {+ ...headers,+ 'host': appUrl.host,+ 'x-forwarded-host': appUrl.host,+ 'x-forwarded-proto': appUrl.protocol.replace(':', ''),+ };+};+/*** Create a Node.js HTTP request object for OIDC Provider* @param req Next.js request object@@ -64,7 +82,7 @@ export const createNodeRequest = async (req: NextRequest): Promise<IncomingMessa*/const nodeRequest = Object.assign(bodyStream, {// Basic properties- headers: convertHeadersToNodeHeaders(req.headers),+ headers: pinHostToAppUrl(convertHeadersToNodeHeaders(req.headers)),method: req.method,// Add extra properties expected by the Node.js server