diff --git a/src/app/api/auth/callback/route.ts b/src/app/api/auth/callback/route.ts index a4b436b..580416b 100644 --- a/src/app/api/auth/callback/route.ts +++ b/src/app/api/auth/callback/route.ts @@ -1,4 +1,4 @@ -import { STATE_COOKIE, appOrigin, callbackUrl, redirect, safeNext, splitAuth, stateCookie } from '@/lib/auth-flow'; +import { STATE_COOKIE, appOrigin, callbackUrl, onAuthHost, redirect, safeNext, splitAuth, stateCookie } from '@/lib/auth-flow'; import { safeEqual } from '@/lib/crypto'; import { githubRequest } from '@/lib/github'; import { createSession, createTicket, exchangeCode, readCookie, sessionCookie } from '@/lib/session'; @@ -13,6 +13,11 @@ const failPage = (msg: string) => }); export async function GET(req: Request) { + // With a separate sign-in host, the custom domain has no OAuth callback at all: nothing there receives a + // GitHub code, which is what Safe Browsing flagged as deceptive (accounts design, "Sign-in host"). + if (splitAuth(req) && !onAuthHost(req)) { + return new Response('Not found', { status: 404, headers: { 'Cache-Control': 'no-store', 'X-Robots-Tag': 'noindex' } }); + } const q = new URL(req.url).searchParams; const code = q.get('code'); const state = q.get('state'); diff --git a/src/lib/__tests__/auth-handoff.test.ts b/src/lib/__tests__/auth-handoff.test.ts index 9bdde51..9604de0 100644 --- a/src/lib/__tests__/auth-handoff.test.ts +++ b/src/lib/__tests__/auth-handoff.test.ts @@ -76,3 +76,11 @@ describe('sign in on the Vercel host, session on the custom domain', () => { expect(r.headers.get('location')).toBe('/?signin=expired'); }); }); + +describe('no OAuth callback on the custom domain', () => { + it('answers 404 there, even with a code and state', async () => { + const r = await callback(new Request(`${APP}/api/auth/callback?code=c&state=s&iss=https://github.com/login/oauth`)); + expect(r.status).toBe(404); + expect(r.headers.get('location')).toBeNull(); + }); +});