Repository navigation
COG-1159: W1 · Add GET /api/csrf token-bootstrap endpoint (204) - #334
Open
patrickbradley-cog wants to merge 1 commit into
Open
patrickbradley-cog wants to merge 1 commit into
patrickbradley-cog wants to merge 1 commit into
Conversation
Co-Authored-By: patrick.bradley <patrick.bradley@cognition.ai>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Comment on lines
+35
to
+36
| mockMvc.perform(get("/api/csrf")) | ||
| .andExpect(status().isNoContent()); |
There was a problem hiding this comment.
There was a problem hiding this comment.
This is intentional, per COG-1159. CSRF is still disabled on Boot 1.5.4, so the ticket scopes this test to the 204 only. A cookie assertion would fail today. Asserting that XSRF-TOKEN is set belongs with W2, where SecurityConfig switches to CookieCsrfTokenRepository. I checked that flow manually on a throwaway local build: GET /api/csrf returned 204 with Set-Cookie: XSRF-TOKEN=…. The details are in the PR description.
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.
Linear: COG-1159 · Project P-COG-46 (Spring Boot 1.5.4 → 4.1 Migration · UserFront) · Wave W1
Summary
Adds a safe, unauthenticated
GET /api/csrfthat returns204 No Content, so AdminPortal can obtain theXSRF-TOKENcookie before its firstPOST /indexonce W2 turns CSRF on withCookieCsrfTokenRepository. Forward-compatible on Boot 1.5.4; no Boot/Java bump.Note on
token.getToken(): the ticket says injectingCsrfTokenis enough to materialise the token. That holds on Spring Security 4.2 (CsrfFiltersaves the token eagerly). On Spring Security 6 (the Boot 4 target) tokens are deferred, and the cookie is only written once the token value is read. So the handler reads it explicitly, and the endpoint keeps working after the pivot without another change.CsrfResourceTest(@WebMvcTest+ the realSecurityConfig) asserts only the 204 for an anonymous client. Its Javadoc explains that the cookie shows up only once CSRF is enabled, so the test stays green through W2.Merge order: merge this after the W0 smoke suite (#106, #108, #109). The only overlap with COG-1152 (SecurityConfig hygiene) is the one-line
PUBLIC_MATCHERSaddition. Whichever of the two lands second should rebase on top of the first rather than revert it.Verification
JDK: Temurin 8 (1.8), MySQL 5.7 in docker on :3306 (
onlinebanking, credentials fromapplication.properties).The first
mvn verifyrun failed in the existingcontextLoadswith anSSLHandshakeException. This is an environment issue: modern JDK 8 disables TLSv1/1.1, and connector 5.1.42 tries them against MySQL 5.7. It is not caused by this change. I addeduseSSL=falsethrough an env override only, with no repo change:Running the app jar against MySQL, anonymous client:
W2 preview. This was a throwaway local build with
.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())and was not committed. It shows the bootstrap flow this endpoint enables:The repo has no CI workflows. AdminPortal is untouched: making the client call
/api/csrffirst is outside this ticket's scope.Link to Devin session: https://app.devin.ai/sessions/dcc3c806c39c49b68b3e23cd9aababc7
Open in Devin Desktop: https://app.devin.ai/desktop/session/dcc3c806c39c49b68b3e23cd9aababc7?variant=devin
Requested by: @patrickbradley-cog
Devin Review