From 7b38270765949ebb8e4164085716b17462aaabeb Mon Sep 17 00:00:00 2001 From: sykosyber Date: Mon, 12 Oct 2026 16:16:13 -0700 Subject: [PATCH 1/2] Codex: compare OAuth state as bytes, and document both local callback URIs A non-ASCII state of the right length in characters made timingSafeEqual throw (500) instead of refusing the sign-in. And localhost and 127.0.0.1 are different origins to Google, so local setup needs both redirect URIs. Co-Authored-By: Claude Opus 5.5 --- .env.example | 5 ++++- DEPLOYMENT.md | 6 ++++-- src/core/services/server/oauthConnect.test.ts | 6 ++++++ src/core/services/server/oauthConnect.ts | 6 +++++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index 050cc5e..b74e87c 100644 --- a/.env.example +++ b/.env.example @@ -82,7 +82,10 @@ METACULUS_API_KEY= # sign in with read-only access. Register an OAuth client of type "Web # application" in Google Cloud and add the redirect URI # /api/oauth/google/callback -# (http://127.0.0.1:3000/api/oauth/google/callback for `npm run dev`). +# for each origin you open Flyspace at. Google matches it exactly, and +# localhost and 127.0.0.1 are different origins, so for `npm run dev` add both +# http://localhost:3000/api/oauth/google/callback +# http://127.0.0.1:3000/api/oauth/google/callback # Server-side only; the secret never reaches the browser. The access token # goes to the page that asked, for that session. Off in the public preview. # OMNI_OAUTH_ORIGIN pins the redirect origin when a proxy hides it. diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md index d2a316d..f6aa139 100644 --- a/DEPLOYMENT.md +++ b/DEPLOYMENT.md @@ -184,8 +184,10 @@ Google" for blocks that read the person's own Google data 2. Configure the OAuth consent screen. While it is in Testing, only the test users you list can sign in, and Google shows them an unverified-app notice. 3. Create an OAuth client of type "Web application" with the authorized - redirect URI `/api/oauth/google/callback`. Set `OMNI_OAUTH_ORIGIN` - when the server cannot see its public origin. + redirect URI `/api/oauth/google/callback` for every origin people + open Flyspace at. Google matches it exactly: for local use add both + `http://localhost:3000/...` and `http://127.0.0.1:3000/...`. Set + `OMNI_OAUTH_ORIGIN` when the server cannot see its public origin. Flyspace only asks for scopes ending in `.readonly`, checks that the person granted them, requests no refresh token, and stores nothing on the server. The diff --git a/src/core/services/server/oauthConnect.test.ts b/src/core/services/server/oauthConnect.test.ts index 6d14407..3dafa4c 100644 --- a/src/core/services/server/oauthConnect.test.ts +++ b/src/core/services/server/oauthConnect.test.ts @@ -86,6 +86,12 @@ describe('Connect: finishing a sign-in', () => { expect(await finish({ state: `${state.slice(0, -1)}x`, cookie })).toMatchObject({ ok: false, error: 'This sign-in was not started in this browser' }); }); + it('refuses a non-ASCII state of the same length without throwing', async () => { + const { cookie, state } = started(); + const result = await finish({ state: 'é'.repeat(state.length), cookie }); + expect(result).toMatchObject({ ok: false, error: 'This sign-in was not started in this browser' }); + }); + it('refuses a flow older than ten minutes', async () => { const { cookie, state } = started(0); expect(await finish({ state, cookie, now: 10 * 60_000 + 1 })).toMatchObject({ ok: false, nonce: NONCE, error: 'This sign-in took too long; try again' }); diff --git a/src/core/services/server/oauthConnect.ts b/src/core/services/server/oauthConnect.ts index 255d1cb..d1f8ff8 100644 --- a/src/core/services/server/oauthConnect.ts +++ b/src/core/services/server/oauthConnect.ts @@ -165,7 +165,11 @@ export async function finishConnect(args: { if (!flow || flow.provider !== provider.id) return { ok: false, error: 'This sign-in was not started in this browser' }; if ((args.now ?? Date.now()) > flow.exp) return { ok: false, nonce: flow.nonce, error: 'This sign-in took too long; try again' }; const state = args.query.get('state') ?? ''; - const stateMatches = state.length === flow.state.length && timingSafeEqual(Buffer.from(state), Buffer.from(flow.state)); + // Compared as bytes: a non-ASCII state of the same length in characters + // is a different length in bytes, and timingSafeEqual throws on that. + const given = Buffer.from(state); + const expected = Buffer.from(flow.state); + const stateMatches = given.length === expected.length && timingSafeEqual(given, expected); if (!stateMatches) return { ok: false, nonce: flow.nonce, error: 'This sign-in was not started in this browser' }; if (args.query.get('error')) { return { ok: false, nonce: flow.nonce, error: args.query.get('error') === 'access_denied' ? 'Sign-in was cancelled' : 'The provider refused the sign-in' }; From f62fae5c55e206f208ccf90fb8cd9070111bbf19 Mon Sep 17 00:00:00 2001 From: "claude[bot]" <41898282+claude[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2026 23:19:19 +0000 Subject: [PATCH 2/2] Codex: spell out full local OAuth callback URIs Co-Authored-By: Claude Sonnet 5.5 --- DEPLOYMENT.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md index f6aa139..e638be4 100644 --- a/DEPLOYMENT.md +++ b/DEPLOYMENT.md @@ -186,7 +186,8 @@ Google" for blocks that read the person's own Google data 3. Create an OAuth client of type "Web application" with the authorized redirect URI `/api/oauth/google/callback` for every origin people open Flyspace at. Google matches it exactly: for local use add both - `http://localhost:3000/...` and `http://127.0.0.1:3000/...`. Set + `http://localhost:3000/api/oauth/google/callback` and + `http://127.0.0.1:3000/api/oauth/google/callback`. Set `OMNI_OAUTH_ORIGIN` when the server cannot see its public origin. Flyspace only asks for scopes ending in `.readonly`, checks that the person