Skip to content

Verify OAuth state in GitHub callback - #1676

Open
tynianov1 wants to merge 1 commit into
Thinkmill:mainfrom
tynianov1:fix/oauth-state-validation
Open

tynianov1 wants to merge 1 commit into
Thinkmill:mainfrom
tynianov1:fix/oauth-state-validation

Conversation

@tynianov1

Copy link
Copy Markdown

Refs #1669 (the OAuth state part).
Tracked as CVE-2026-129945.

What changed:

  • The GitHub login route always sends a random state and sets a short lived (10 minutes) httpOnly cookie for it, also when there is no from path.
  • The callback returns 400 before exchanging the code when state is missing or has no matching cookie, and clears the cookie on success.
  • The GitHub App install popup (state=close) no longer exchanges the code or sets cookies. When the popup closes, the fork dialog refreshes the token best effort through the existing refresh-token route and continues with the existing token if that fails.

Behavior note: anyone in the middle of signing in during the upgrade will need to start sign-in again.

Testing: added packages/keystatic/src/api/generic.test.ts (handler level: missing state, missing cookie, mismatched cookie, valid sign-in with the state cookie cleared, the state=close popup, login without from), packages/keystatic/src/api/generic.integration.test.ts (the real login and callback handlers behind a Node http server, with the GitHub token endpoint stubbed: normal login, deep link from, a forged callback with another browser's state, and state=close) and packages/keystatic/src/app/fork-repo.test.tsx (refresh before refetch, and the flow continuing when the refresh fails or returns 401). Ran vitest for the keystatic project, tsc, eslint and prettier.

Notes: The state=close path no longer exchanges the code. After the install popup closes, the client refreshes the token best-effort, so the flow keeps a fresh token without accepting an unbound code.

The GitHub login now always sets a short lived state cookie, also when
there is no from path. The callback rejects requests without a matching
state cookie before exchanging the code, and clears the cookie on
success. The GitHub App install popup (state=close) no longer exchanges
the code. After the popup closes, the fork dialog refreshes the token
best effort and continues with the existing token if that fails.

Refs Thinkmill#1669
@tynianov1
tynianov1 requested a review from emmatown as a code owner November 20, 2026 14:02
@changeset-bot

changeset-bot Bot commented Nov 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7b3a376

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@keystatic/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant