Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/app/api/auth/callback/route.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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');
Expand Down
8 changes: 8 additions & 0 deletions src/lib/__tests__/auth-handoff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Loading