fix(security): enable CSRF protection for state-changing requests#327
Draft
Isaries wants to merge 2 commits into
Draft
fix(security): enable CSRF protection for state-changing requests#327Isaries wants to merge 2 commits into
Isaries wants to merge 2 commits into
Conversation
CSRF protection was disabled site-wide, so any authenticated session could be driven by a forged cross-site request. Because authentication relies on a session cookie that the browser attaches automatically, a malicious page could trigger state-changing actions (password changes, account edits, run management) on behalf of a signed-in user without their knowledge. Enable CSRF using a cookie-based token repository so the token is readable by the single page application and echoed back in a request header, matching the client framework defaults. Add a filter that forces the token cookie to be written on requests that do not otherwise read it, since the token is loaded lazily.
Enabling CSRF protection also applies to the server rendered admin and teacher portal pages. Their jQuery POST requests and one plain HTML form did not send the token, so those actions (enabling or disabling users, managing roles, portal settings, deleting news, listing and importing projects, impersonating users) would be rejected with a 403. Add a shared handler in the common portal script that echoes the token cookie back in a request header on state changing same origin requests, include that script on the two pages that lacked it, and add the token field to the plain import form. Spring form tag pages already receive the token automatically.
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
CSRF protection was disabled site-wide. Because authentication relies on a session cookie that the browser attaches automatically, a malicious page could drive state-changing actions on behalf of a signed-in user. This enables CSRF protection.
Changes
Why this is a draft
Enabling CSRF affects every state-changing request, so it needs verification on a running instance before merging:
The WebSocket same-origin re-enable is intentionally out of scope; it would need client side token handling and its own verification.
Testing
mvnw package).