Skip to content

fix(security)!: add security headers and sign out with a CSRF token - #71

Merged
KFilippopolitis merged 6 commits into
masterfrom
fix/security-headers
Nov 6, 2026
Merged

KFilippopolitis merged 6 commits into
masterfrom
fix/security-headers

Conversation

@KFilippopolitis

Copy link
Copy Markdown
Contributor

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

  • nginx adds HSTS, nosniff, X-Frame-Options, Referrer-Policy and an enforced Content-Security-Policy on the pages it serves itself, and turns server_tokens off. /services and JupyterHub keep their own headers.
  • KEYCLOAK_ORIGIN (default https://iam.ebrains.eu) names the Keycloak the CSP allows for the account page's token request.
  • inlineCritical is off. Its inlined loader script would be blocked by the CSP and leave stylesheets stuck on print-only.
  • Sign-out is a full-page POST with the XSRF-TOKEN cookie 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

  • A CSP mistake shows up as a broken page rather than a failed test. Violations appear in the browser console.
  • First paint can change slightly, because critical CSS is no longer inlined.

Rollback

Revert together with the backend PR.

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.
@KFilippopolitis
KFilippopolitis merged commit 8b17318 into master Nov 6, 2026
16 checks passed
@KFilippopolitis
KFilippopolitis deleted the fix/security-headers branch November 11, 2026 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant