From 2b060c0cabbb06e03f37a9f92aae46ac370ac28b Mon Sep 17 00:00:00 2001 From: Max Farrell Date: Thu, 5 Nov 2026 19:40:27 -0600 Subject: [PATCH] Fix OAuth consent Connect button failing with a cross-site POST error The consent page set Referrer-Policy: no-referrer. Browsers then send 'Origin: null' on the page's own same-origin form POST, which SvelteKit's CSRF check rejects ('Cross-site POST form submissions are forbidden'). Use same-origin so the real Origin is sent, and assert it in the OAuth smoke test (which previously set Origin by hand and could not see this). Co-Authored-By: Claude Sonnet 5.5 --- scripts/oauth-smoke.mjs | 7 +++++++ src/routes/admin/oauth/authorize/+server.ts | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/oauth-smoke.mjs b/scripts/oauth-smoke.mjs index 9f4083d..b5221c3 100644 --- a/scripts/oauth-smoke.mjs +++ b/scripts/oauth-smoke.mjs @@ -92,6 +92,13 @@ export async function testOAuth({ response.headers.get('content-security-policy') ?? '', /frame-ancestors 'none'/, ); + // A browser sends "Origin: null" on this page's same-origin POST under 'no-referrer', which the + // CSRF check rejects, so the Connect button would fail for real users. + assert.equal( + response.headers.get('referrer-policy'), + 'same-origin', + 'consent page must keep real same-origin Origin headers on its form post', + ); const handle = /name="handle"\s+value="([^"]+)"/.exec(html)?.[1]; assert.ok(handle, 'browser-bound consent handle rendered'); const cookie = response.headers diff --git a/src/routes/admin/oauth/authorize/+server.ts b/src/routes/admin/oauth/authorize/+server.ts index cbbc5da..9f59603 100644 --- a/src/routes/admin/oauth/authorize/+server.ts +++ b/src/routes/admin/oauth/authorize/+server.ts @@ -24,7 +24,9 @@ function page(body: string, status = 200, extra?: Headers) { headers.set('Content-Type', 'text/html; charset=utf-8'); headers.set('Cache-Control', 'no-store'); headers.set('X-Frame-Options', 'DENY'); - headers.set('Referrer-Policy', 'no-referrer'); + // Not 'no-referrer': browsers then send "Origin: null" on the page's own same-origin form POST, + // which the CSRF check rightly rejects ("Cross-site POST form submissions are forbidden"). + headers.set('Referrer-Policy', 'same-origin'); headers.set( 'Content-Security-Policy', "default-src 'none'; style-src 'unsafe-inline'; form-action 'self'; frame-ancestors 'none'; base-uri 'none'",