Repository navigation
Re-enable CSRF protection on deposit/withdraw/transfer forms - #375
Open
devin-ai-integration[bot] wants to merge 5 commits into
Open
devin-ai-integration[bot] wants to merge 5 commits into
devin-ai-integration[bot] wants to merge 5 commits into
Conversation
…cookie Co-Authored-By: james.scarr <jamesscarr6@gmail.com>
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Co-Authored-By: james.scarr <jamesscarr6@gmail.com>
Co-Authored-By: james.scarr <jamesscarr6@gmail.com>
Co-Authored-By: james.scarr <jamesscarr6@gmail.com>
This branch has not been deployed
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.
Summary
Fixes code scan finding
sfind-4627fb15d87d4057a2e619d80fc350b0(scanscan-85ec232d98d341f1a872ff09167256d1):SecurityConfigcalledcsrf.disable(), so a page on any other site could submitPOST /transfer,/withdrawor/depositas a logged-in user using only the session cookie.SecurityConfig: removed.csrf(csrf -> csrf.disable()), so Spring Security'sCsrfFilterruns again. Logout matcher is nownew AntPathRequestMatcher("/logout", "POST"). A GET logout link with CSRF on would still let any site log users out.th:action="@{/...}"(deposit,withdraw,transfer,login,register), so Thymeleaf adds the hidden_csrffield.dashboard.html/transactions.html: the item is still<a class="nav-link" href="/logout">Logout</a>, which the Cypress spec asserts. Itsonclicknow submits the surrounding#logout-form(POST +_csrf). Without JavaScript, a<noscript>submit button takes the link's place.application.properties:server.servlet.session.cookie.same-site=laxandhttp-only=trueas a second layer.BankControllerCsrfTest(@WebMvcTest+SecurityConfig): checks deposit, withdraw and transfer each return 403 withoutcsrf()(and the service is never called) and succeed with it. Also checks that the dashboard renders a_csrffield and that logout is POST-only.Verification
./mvnw test: 10/10 pass (9 new +contextLoads). The Cypress e2e smoke suite passes in CI../mvnw spring-boot:run) tested with curl:JSESSIONID=...; HttpOnly; SameSite=Lax.POST /transferand/withdrawwith only the victim'sJSESSIONIDcookie (plus anOrigin: https://evil.exampleheader) return 403, and the balance stays at $1000.00._csrftoken return 302 (deposit gives $1000, transfer of 200 gives $800).GET /logoutreturns 404. A#logout-formPOST redirects to/login?logout, and the session is invalidated.Note: any non-browser client that POSTs to these endpoints now has to send the CSRF token.
Link to Devin session: https://devin-gtm.devinenterprise.com/sessions/bd574ed76fed416596e8c18055a6c3c5
Open in Devin Desktop: https://devin-gtm.devinenterprise.com/desktop/session/bd574ed76fed416596e8c18055a6c3c5?variant=devin
Devin Review