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'",