Repository navigation
fix(security): harden dsAuthInfo auth cookie with Secure and SameSite - #1663
Merged
Merged
Conversation
Set secure and sameSite='lax' on the auth JWT cookie written in storeToken(), as defense-in-depth. The Secure flag is derived from the actual page protocol (location.protocol === 'https:') so it is applied on any https page, including behind a TLS-terminating reverse proxy, while local http dev still works. 'lax' is used rather than 'strict' so the cookie is still sent on the top-level navigation that returns from external authentication.
There was a problem hiding this comment.
🔵 Needs a closer look
Upgrade or replace the cookie serializer so SameSite=Lax is actually written.
No open issues 🎉
What changed in this PR
This pull request hardens the client-side dsAuthInfo authentication cookie against transport and cross-site risks.
Changes:
- Derives the
Secureattribute from the page’s actual protocol. - Requests
SameSite=Laxwhile preserving external authentication redirects. - Adds HTTPS and HTTP unit-test coverage.
- The pinned
js-cookie2.2.1 does not serializesameSite, so the dependency or serialization support must be updated for the protection to take effect.
| File | Reviewed changes |
|---|---|
src/app/core/auth/auth.service.ts |
Adds transport-aware Secure and SameSite=Lax cookie options; SameSite is currently not emitted by the pinned serializer. |
src/app/core/auth/auth.service.spec.ts |
Verifies the expected cookie options for HTTPS and HTTP transports. |
Review effort: Lite
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.
Security hardening — auth cookie (
dsAuthInfo)Part of dataquest-dev/dspace-customers#1104 (R35, defense-in-depth), see #1083.
Problem
The Angular app stores the auth JWT in the
dsAuthInfocookie, which is readable from JavaScript (it must be — SSR reads it, so it cannot beHttpOnly). The cookie was written without theSecureorSameSiteattributes, so it could be sent over plain HTTP and on cross-site requests, widening the blast radius of any XSS or network position.Change
In
AuthService.storeToken(), set two attributes on the cookie:Secure— derived from the actual page transport (location.protocol === 'https:'via the existingNativeWindowService), not a config flag. This correctly marks the cookie Secure behind a TLS-terminating reverse proxy/ingress (the common production setup, where the Node server itself runs plain HTTP), while leaving it unset for local HTTP development.SameSite=Lax— blocks the cookie on cross-site subrequests while still allowing it on top-level navigations, which the external-auth (Shibboleth/ORCID) redirect flow relies on.Strictwould break those inbound navigations, soLaxis the correct level.storeToken()is the only place this cookie is written (verified), so this covers the login and token-refresh paths. SSR writes no cookies, so no server-side change is needed.Note
This is defense-in-depth. The primary mitigation for the stored-XSS vector is the backend inline-disposition fix (separate PR); this change limits what a successful XSS could do with the token.
Tests
Unit tests assert the cookie is written with
secure: trueon HTTPS,secure: falseon HTTP, andsameSite: 'lax'in both cases.🤖 Generated with Claude Code