Repository navigation
fix(security)!: add security headers and sign out with a CSRF token - #71
Merged
Merged
Conversation
The Angular pages, including the one that shows a refresh token, had no HSTS, nosniff, frame or referrer protection, and nginx named its version. Add them per location, so /services and JupyterHub keep their own, and turn server_tokens off. A full Content-Security-Policy goes in report-only until checked in a browser; KEYCLOAK_ORIGIN names the token endpoint it allows.
The backend no longer accepts sign-out without its token, and the default logout page's token does not match.
Checked in a browser against a local Keycloak: dashboard, account page and creating a mip token raise no violations. The one violation was Angular's inlined critical-CSS loader, which blocked would have left stylesheets stuck on media=print, so inlineCritical is off.
…ook iframe under the CSP captureSvg loads charts from a blob: URL, which img-src refused, so D3 exports silently fell back to html2canvas. A Hub re-login inside the Lab iframe redirects through Keycloak, which frame-src refused, leaving a dead frame.
Without the XSRF-TOKEN cookie, for example after signing out in another tab, the POST only got a raw 403 page. Read the token through HttpXsrfTokenExtractor, so a malformed cookie can no longer throw before the form submits.
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
Security headers on the portal's own pages, and a sign-out that carries the CSRF token. From an audit against the OWASP cheat sheets and ASVS 5.
Deploy together with platform-backend
fix/owasp-token-session-hardening: the old UI's sign-out fails on that backend.Changes
nosniff,X-Frame-Options,Referrer-Policyand an enforced Content-Security-Policy on the pages it serves itself, and turnsserver_tokensoff./servicesand JupyterHub keep their own headers.KEYCLOAK_ORIGIN(defaulthttps://iam.ebrains.eu) names the Keycloak the CSP allows for the account page's token request.inlineCriticalis off. Its inlined loader script would be blocked by the CSP and leave stylesheets stuck on print-only.XSRF-TOKENcookie value.Tests
npx ng test --watch=false: 1145 pass. The image builds.Run locally in a browser with the CSP enforced, against a Keycloak 26 container and the new backend: the dashboard rendered without CSP violations, the account page created a mip token, and Sign Out returned to Keycloak login.
All testing was local. Nothing has run against the EBRAINS realm or a real cluster. The studio page and the notebook iframe were not exercised under the CSP.
Risks
Rollback
Revert together with the backend PR.