Skip to content

fix(security): harden dsAuthInfo auth cookie with Secure and SameSite - #1663

Merged
milanmajchrak merged 2 commits into
dtq-devfrom
sec/auth-cookie-hardening
Oct 28, 2026
Merged

milanmajchrak merged 2 commits into
dtq-devfrom
sec/auth-cookie-hardening

Conversation

@Kasinhou

Copy link
Copy Markdown

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 dsAuthInfo cookie, which is readable from JavaScript (it must be — SSR reads it, so it cannot be HttpOnly). The cookie was written without the Secure or SameSite attributes, 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 existing NativeWindowService), 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. Strict would break those inbound navigations, so Lax is 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: true on HTTPS, secure: false on HTTP, and sameSite: 'lax' in both cases.

🤖 Generated with Claude Code

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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 Secure attribute from the page’s actual protocol.
  • Requests SameSite=Lax while preserving external authentication redirects.
  • Adds HTTPS and HTTP unit-test coverage.
  • The pinned js-cookie 2.2.1 does not serialize sameSite, 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

@Kasinhou
Kasinhou requested a lite review from Copilot October 27, 2026 13:33
@Kasinhou
Kasinhou requested review from milanmajchrak and removed request for Copilot October 27, 2026 13:39
@milanmajchrak
milanmajchrak merged commit 9bcd483 into dtq-dev Oct 28, 2026
6 checks passed
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.

3 participants