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
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
# <your origin>/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.
Expand Down
7 changes: 5 additions & 2 deletions DEPLOYMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,11 @@ 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 `<origin>/api/oauth/google/callback`. Set `OMNI_OAUTH_ORIGIN`
when the server cannot see its public origin.
redirect URI `<origin>/api/oauth/google/callback` for every origin people
open Flyspace at. Google matches it exactly: for local use add both
`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
granted them, requests no refresh token, and stores nothing on the server. The
Expand Down
6 changes: 6 additions & 0 deletions src/core/services/server/oauthConnect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand Down
6 changes: 5 additions & 1 deletion src/core/services/server/oauthConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' };
Expand Down
Loading