Validate Forge GitHub OAuth state#15812
Open
jamesfredley wants to merge 1 commit into
Open
Conversation
Persist generated GitHub OAuth state in a path-scoped HttpOnly cookie and validate callbacks before exchanging GitHub codes. Reject missing or mismatched callback states without mutating outstanding OAuth state cookies, and consume only the returned valid state so concurrent flows can continue. Assisted-by: Hephaestus:openai/gpt-5.5 codex-review review-gate
Contributor
There was a problem hiding this comment.
Pull request overview
This PR strengthens the Grails Forge GitHub OAuth flow by persisting the OAuth state in a path-scoped HttpOnly cookie and validating it on callback endpoints before proceeding, including support for multiple outstanding states.
Changes:
- Add state generation, persistence, validation, and consumption via a path-scoped OAuth state cookie.
- Enforce state validation for both normal and error callbacks, rejecting missing/mismatched state before exchanging OAuth codes.
- Add a new Spock spec covering redirect/callback state cookie behavior, including multiple outstanding flows.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| grails-forge/grails-forge-api/src/test/groovy/org/grails/forge/api/create/github/GitHubOAuthStateSpec.groovy | Adds test coverage for OAuth state cookie issuance, validation, and consumption across redirect/callback scenarios. |
| grails-forge/grails-forge-api/src/main/java/org/grails/forge/api/create/github/GitHubRedirectService.java | Introduces cookie construction/expiry/consumption helpers and wires state into the GitHub authorize URL. |
| grails-forge/grails-forge-api/src/main/java/org/grails/forge/api/create/github/GitHubCreateController.java | Applies state validation and cookie mutation rules to the create endpoint and the OAuth error callback endpoint. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| throw e; | ||
| } else { | ||
| return HttpResponse.temporaryRedirect(redirectService.constructGrailsForgeErrorRedirectUrl(e.getMessage())); | ||
| return consumeOAuthStateCookie(HttpResponse.temporaryRedirect(redirectService.constructGrailsForgeErrorRedirectUrl(e.getMessage())), requestInfo, state); |
| if (!hasValidOAuthState(state)) { | ||
| return rejectInvalidOAuthState(redirectService.getLauncherURI()); | ||
| } | ||
| redirect = redirectService.constructGrailsForgeErrorRedirectUrl(errorDescription); |
| .queryParam("state", state) | ||
| .build(); | ||
| } catch (Exception e) { | ||
| String msg = "Failed to construct redirect URI using request " + requestInfo + " to GiHub OAuth: " + e.getMessage(); |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 8.0.x #15812 +/- ##
==================================================
+ Coverage 49.4842% 49.5026% +0.0184%
- Complexity 16697 16702 +5
==================================================
Files 1947 1947
Lines 92474 92474
Branches 16152 16152
==================================================
+ Hits 45760 45777 +17
+ Misses 39606 39588 -18
- Partials 7108 7109 +1 🚀 New features to boost your workflow:
|
✅ All tests passed ✅🏷️ Commit: e471132 Learn more about TestLens at testlens.app. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Problem
The Forge GitHub "Create in GitHub" flow starts an OAuth authorization request but never tied the returned callback back to the request that started it. The OAuth
statevalue was not persisted server-side and was not checked when GitHub redirected the user back with an authorizationcode.Without a bound, verified
state:code.The Fix
State is now generated up front, persisted, and validated on the way back before any code exchange happens.
statein a path-scoped,HttpOnlycookie when the authorization request is created, so the callback can be verified against it.stateagainst the stored value before exchanging the GitHub authorization code. Nostate, no exchange.Files
GitHubRedirectService.java- issue, store, look up, and consume the path-scopedHttpOnlystate cookie.GitHubCreateController.java- validate callbackstate(success and error paths) before code exchange; reject on missing/mismatch.GitHubOAuthStateSpec.groovy- new spec covering issuance, happy-path validation, missing/mismatched rejection, non-mutation of other outstanding states, and concurrent-flow consumption.Testing
:grails-forge-api:test --tests "org.grails.forge.api.create.github.GitHubOAuthStateSpec"and the full:grails-forge-api:testmodule suite pass.clean aggregateViolations :grails-test-report:check) clean.