Architecture Decision Record
ADR-022: Browser Session-Cookie Authentication for Blazor SSR
Status
Accepted. Extended by ADR-131 (the same-origin API proxy). Revised
2026-10-06: both apps run the same-origin API proxy, so the server writes the session cookies, the
browser receives only a claims-only token, and SameSite is a configured value (Lax in both apps).
Revised 2026-10-07: anchors refreshed after the v1.233.0 release. Revised 2026-10-21: anchors
refreshed after the v1.247.0 release. Revised 2026-10-26: the X-CSRF gate is documented with
its one exemption (an HTTP/2 WebSocket extended CONNECT, held to the same-origin check instead),
and anchors refreshed after the v1.255.0 consumer adoption. Revised 2026-10-28: anchors refreshed
after the v1.265.1 consumer adoption. Revised 2026-11-23: auth/passkeys/signin is documented as the
fifth token-issuing path, the view-as overlay answer on both token endpoints (ADR-137) and the
/auth/session/handoff endpoint are named, the proxy registration is credited to
AddMmcaBlazorWebHost, and anchors refreshed. Revised 2026-12-03 (MMCA.Common v1.331.0):
DELETE /auth/session-cookie ends the refresh session behind the cookie before deleting it, through
the identity endpoint's anonymous POST auth/session/end, and expires a present view-as overlay; the
cookie bullets now state that the server is the only writer, with no browser seed endpoint; see
Revision (2026-12-03).
Context
The apps are Blazor Web Apps: a server-rendered (SSR) prerender pass runs on the first request, then
an interactive phase (Blazor Server or WebAssembly) takes over. Authentication against the API is
JWT-based (ADR-004): login returns an access token plus a refresh token, and the gateway expects the
access token as a bearer header on API calls. (In both apps the WebAssembly client and the
notification hub now call the same-origin proxy
(MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/SameOriginProxy/SameOriginApiProxyServiceExtensions.cs:24-25),
which attaches that bearer from the HttpOnly cookie (SameOriginApiProxyEndpoint.cs:110,
SameOriginProxyTransformer.cs:77); see ADR-131.) That leaves a gap on fresh GET requests
the browser issues directly: a deep link, an F5 refresh, or "open in new tab" of an [Authorize]
page. At SSR-prerender time there is no interactive client yet and no Authorization header, so
[Authorize] would fail and bounce the user to /login even though they are logged in. Storing the
JWT in localStorage does not help: SSR runs on the server and cannot read it, and exposing the
refresh token to JavaScript is an XSS-exfiltration risk.
Decision
Carry the session in HttpOnly cookies and add an authentication scheme that reads them during SSR
prerender. The mechanism ships in MMCA.Common.API (SessionCookies/) with a MMCA.Common.UI
companion, and both apps' Web UI hosts wire it.
- Two HttpOnly cookies, written only by the server.
mmca_auth_access(the JWT, stored DataProtection-protected) andmmca_auth_refresh(the refresh token) (MMCA.Common/Source/Presentation/MMCA.Common.API/SessionCookies/SessionCookieEndpoints.cs:23-24,:32). No endpoint takes a token from the browser: the server is the only writer, throughISessionCookieStore(.../SessionCookies/ISessionCookieStore.cs:17, which appends withSessionCookieJarat:39) and the server-side refresher (CookieSessionRefresher.cs:150), as the endpoint class states (SessionCookieEndpoints.cs:16-18). Both apps run the same-origin proxy:AddMmcaBlazorWebHostregisters it for every Blazor Web host (MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/Hosting/BlazorWebHostExtensions.cs:142, called atMMCA.ADC/Source/Hosts/UI/MMCA.ADC.UI.Web/Program.cs:28andMMCA.Store/Source/Hosts/UI/MMCA.Store.UI.Web/Program.cs:30), andUseMmcaBlazorWebPipeline(BlazorWebHostExtensions.cs:181) maps it throughMapCommonSameOriginApiProxy(:213), called at ADCProgram.cs:120and:122and StoreProgram.cs:86. The cookies are written on two paths: by the proxy transformer on a successful response from a token-issuing path,auth/login,auth/register,auth/oauth/exchange,auth/sign-in-link/redeemandauth/passkeys/signinplus any a host adds (SameOriginApiProxySettings.cs:33,:54; matched atSameOriginApiProxyEndpoint.cs:327-330), which moves the tokens into the cookies and hands the browser a claims-only token with an empty refresh token instead (SameOriginProxyTransformer.cs:114-117,:258-260); and byPOST /auth/session-cookie/handofffor the Server circuit (SessionHandoffEndpoints.cs:20,:73).DELETE /auth/session-cookieends the session and clears them at logout (SessionCookieEndpoints.cs:49-71; see the next bullet), and a proxied sign-out clears them whatever the upstream answered (SameOriginProxyTransformer.cs:107-112). - Sign-out ends the server session, not only the cookies.
DELETE /auth/session-cookierefuses a cross-site request with 403 first (SessionCookieEndpoints.cs:51-54), then, on a host that calledAddServerAuthSessionCookie, asksICookieSessionEnderto end the refresh session behind the request's refresh cookie (:56-59; registered atMMCA.Common/Source/Presentation/MMCA.Common.API/DependencyInjection.cs:198), then always deletes the session cookies and any view-as overlay cookie (ADR-137) and answers 204 (:61-67). The ender posts the refresh token server-to-server, asEndSessionRequest(RefreshToken), to the identity endpoint'sPOST auth/session/endthrough the same named client the cookie refresher uses, waits at most 5 seconds on its own timeout rather than the request's, and logs a refusal or a failure at Warning without stopping the sign-out (MMCA.Common/Source/Presentation/MMCA.Common.API/SessionCookies/CookieSessionEnder.cs:33,:39,:41-73).AuthControllerBase.EndSessionAsync(MMCA.Common/Source/Presentation/MMCA.Common.API/Controllers/AuthControllerBase.cs:201-215) is anonymous,[NonIdempotent], not throttled (for the same reason asauth/refresh: every Server-circuit sign-out reaches it from the UI host's one address, and a refresh token is high-entropy) and always answers 204, so the answer reveals nothing about the token. It callsIAuthSessionIssuer.SignOutByRefreshTokenAsync, which revokes only the one live session whose token hash matches and treats an empty, unknown, expired or already-revoked token as a no-op, never falling back to the user's other sessions (MMCA.Common/Source/Core/MMCA.Common.Application/Auth/Sessions/IAuthSessionIssuer.cs:117-126,.../Auth/Sessions/AuthSessionIssuer.cs:222-244). This is what makes a Server-circuit sign-out during a view-as session revoke the staff user's own session: the circuit holds only the view-as token, which the UI'sLogoutAsyncspends on the exemptauth/view-as/endrather than onauth/revoke/current(MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/AuthUIService.cs:122-134), so the refresh cookie is the only remaining handle on the staff session. The Server-circuit cookie handoff also expires a present overlay, so a new session never opens on the viewed account (MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/SameOriginProxy/SessionHandoffEndpoints.cs:74-82). - SameSite is a setting.
SessionCookieSettings.SameSitedefaults toLax(MMCA.Common/Source/Presentation/MMCA.Common.API/SessionCookies/SessionCookieSettings.cs:19). The proxy replaces it withSameOriginApiProxy:SessionCookieSameSite(defaultStrict,SameOriginApiProxySettings.cs:116, applied atSameOriginApiProxyServiceExtensions.cs:70), and both apps configureLaxso a signed-in user arriving from a mailed deep link keeps the session on the first server render (MMCA.ADC/Source/Hosts/UI/MMCA.ADC.UI.Web/appsettings.json:86-87,MMCA.Store/Source/Hosts/UI/MMCA.Store.UI.Web/appsettings.json:64-65). - An SSR-time scheme reads the access cookie.
SessionCookieAuthenticationHandler(scheme"SessionCookie") readsmmca_auth_accessduring prerender, parses its claims (SessionCookieAuthenticationHandler.cs:52), checks expiry (:56), and populatesHttpContext.User, so[Authorize]passes on fresh GETs. It does not validate the signature: the cookie was minted by the UI host from a token the API already issued, and the API still fully validates the JWT on every API call (ADR-004). The handler is not the security boundary. Under the proxy the same cookie also authenticates data calls (SessionCookieSettings.cs:15-17), but only by being forwarded as the bearer to the gateway, where the API validates it. - The refresh token never leaves the server.
POST /auth/session/token(SessionCookieEndpoints.cs:78) is a same-origin "validate-or-refresh" endpoint the browser calls to hydrate its in-memory claims;CookieSessionRefresherreads the HttpOnly refresh cookie server-side, refreshes if needed (:98), and the endpoint answers 401no_sessionwhen there is no valid session (:101) or a token plus expiry otherwise (:105-107). That token is alwaysSessionClaimsToken, an unsigned copy of the claims that no API accepts, never the access token (:106;.../SessionCookies/SessionClaimsToken.cs:14,:25). A live view-as overlay cookie (ADR-137) is answered first, also as a claims-only token, without touching the staff user's session and without ever being refreshed (SessionCookieEndpoints.cs:93-96). The circuit's token handoff (POST /auth/session/handoff) also answers a live overlay first and never refreshes it, but hands the circuit the real view-as access token asSessionHandoffProtectorciphertext, not a claims-only token (SessionHandoffEndpoints.cs:19,:40-42). The refresh token is never exposed to JavaScript. - CSRF defense-in-depth. The two cookie endpoints,
DELETE /auth/session-cookieandPOST /auth/session/token, deliberately disable antiforgery (they carry no antiforgery token,SessionCookieEndpoints.cs:71,:111), rest on the cookies'SameSitevalue, and both refuse a cross-site request via theSec-Fetch-Siteheader (:51,:85,IsCrossSiteat:120-122). Under the proxy, unsafe methods on/api/**and both handoff endpoints require theX-CSRF: 1header (SameOriginApiProxyEndpoint.cs:275,SessionHandoffEndpoints.cs:32,:62), which is the CSRF gate the apps rely on rather than SameSite. The one exemption is an HTTP/2 WebSocket extendedCONNECT, which cannot carry the header and is instead held to this host's ownOriginby the proxy's same-origin gate (SameOriginApiProxyEndpoint.cs:148,:186,:275).
This is a backend-for-frontend (BFF) style token-storage layer: the browser holds an HttpOnly session whose refresh half it cannot read, the SSR pass authenticates from the access cookie without trusting it as the security boundary, and the real enforcement stays at the API.
Rationale
- Fixes the fresh-GET prerender gap. Without a server-readable session, every deep-link or F5 to
an
[Authorize]page would redirect to/logindespite a valid session; the cookie scheme closes that without a per-page workaround. - HttpOnly keeps the refresh token out of JS. Storing the refresh token where a script can read it (localStorage) is the classic XSS-exfiltration risk; HttpOnly cookies plus a server-side refresh endpoint keep it inaccessible to scripts.
- Skipping signature validation at SSR is safe because the API is the boundary. The SSR handler only needs the user's claims to render; every state-changing or data-returning call goes to the API, which validates the JWT properly (ADR-004), so prerender does not need to re-verify a cookie the host itself minted.
- Shared in the framework. Both apps face the identical Blazor-Web-App prerender problem, so the scheme, the cookie jar, the endpoints, and the refresher live in MMCA.Common rather than being re-derived per app.
Trade-offs
- A non-validating auth scheme exists.
SessionCookieAuthenticationHandlertrusts a cookie it does not cryptographically verify. This is sound only because (a) the cookie is HttpOnly and host-minted and (b) the API independently validates every call. Authorizing a sensitive action purely on the SSR principal without an API round-trip would break the safety argument. - Cookie and header dual path. The session lives both in cookies (browser GETs / SSR, and proxied
data calls in both apps) and in the Blazor Server circuit's own token store (server-to-server gateway
calls); the two must stay in sync. With the proxy on, the circuit's
ITokenRefresherandISessionCookieSyncare replaced byHandoffTokenRefresherandHandoffSessionCookieSync(SameOriginApiProxyServiceExtensions.cs:79-80), so the sync runs through the protected handoff endpointsPOST /auth/session/handoffandPOST /auth/session-cookie/handoff(SessionHandoffEndpoints.cs:19-20). - CSRF surface. Cookie-based auth reintroduces CSRF considerations a pure bearer-header scheme
avoids; mitigated by the cookies'
SameSitevalue (Lax in both apps), the refresh endpoint'sSec-Fetch-Sitecheck and, under the proxy, theX-CSRFheader on unsafe methods, but it is a surface a header-only design would not have. - Expiry is checked, not cryptographically enforced, at the SSR edge. A tampered cookie yields claims that fail at the API on the next call, but the prerendered HTML for that one pass is produced from unverified claims.
Revision (2026-10-06)
- Both apps run the same-origin API proxy (ADR-131): the browser seed request then answered 204
without writing (the seed endpoint is gone since v1.331.0, Revision 2026-12-03), and the cookies are written server-side by the proxy transformer and the
/auth/session-cookie/handoffendpoint. SameSiteis documented as a setting (default Lax, proxy default Strict, configured Lax in both apps); the proxy'sX-CSRFheader is the CSRF gate on unsafe proxied methods./auth/session/tokenreturns a claims-onlySessionClaimsTokenin both apps, not the access token; the refresh token is still never returned.- The session cookie also authenticates proxied data calls (as the forwarded bearer), not only SSR; the Server circuit syncs through the handoff implementations.
- Status and Related now point to ADR-131. Anchors were added and re-verified against current source.
Revision (2026-10-07)
Re-verified against current source. The decision is unchanged: the server is the only writer of the
session cookies under the proxy, the browser seed request answered 204 without writing, the refresh
endpoint returns a claims-only token and checks Sec-Fetch-Site, and both apps run the proxy. Only
line numbers moved.
- Anchors re-verified against current source:
MMCA.Common/Source/Presentation/MMCA.Common.API/SessionCookies/SessionCookieEndpoints.cs:43(SessionCookieJar.Append),:41-46(the then-current seed guard and 204),:47and:53(DisableAntiforgeryon POST and DELETE),:49-53(DELETE clears the cookies),:60(/auth/session/token),:63(cross-site check),:74-77(SessionClaimsTokenunder claims-only),:78(token plus expiry),:91-93(IsCrossSite);MMCA.ADC/Source/Hosts/UI/MMCA.ADC.UI.Web/Program.cs:161(AddCommonSameOriginApiProxy). The Context anchor for the proxy now citesMMCA.Common/Source/Presentation/MMCA.Common.UI.Web/SameOriginProxy/SameOriginApiProxyServiceExtensions.cs:24-25for the client and hub switch, andSameOriginApiProxyEndpoint.cs:95plusSameOriginProxyTransformer.cs:60for the bearer taken from the HttpOnly cookie.
Revision (2026-10-21)
Re-verified against current source. The decision is unchanged: both apps run the same-origin proxy,
the browser seed request answered 204 without writing, the server writes
the cookies through the proxy transformer and the handoff endpoint, the refresh endpoint returns a
claims-only token and checks Sec-Fetch-Site, and unsafe proxied methods require X-CSRF. Only
line numbers moved (the default-mode POST gained a missing-token 400 check ahead of the cookie
write in v1.247.0, which shifted every later line of SessionCookieEndpoints.cs).
- Anchors re-verified against current source:
MMCA.Common/Source/Presentation/MMCA.Common.API/SessionCookies/SessionCookieEndpoints.cs:52(SessionCookieJar.Append),:41-55(the then-current seed guard and 204),:56and:62(DisableAntiforgeryon POST and DELETE),:58-62(DELETE clears the cookies),:69(/auth/session/token),:72(cross-site check),:84-86(SessionClaimsTokenunder claims-only),:87(token plus expiry),:100-102(IsCrossSite);MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/SameOriginProxy/SameOriginApiProxySettings.cs:32(DefaultTokenIssuingPaths),:98(SessionCookieSameSitedefaultStrict);SameOriginApiProxyEndpoint.cs:108(bearer taken from the session cookie),:264(X-CSRFgate on unsafe methods);MMCA.ADC/Source/Hosts/UI/MMCA.ADC.UI.Web/appsettings.json:69-70(SessionCookieSameSiteLax). Unchanged and re-confirmed:SameOriginApiProxyServiceExtensions.cs:72,:73,:83-84,SameOriginProxyTransformer.cs:60,:141,SessionHandoffEndpoints.cs:17-18,:26,:44,:55, bothProgram.csanchors, andMMCA.Store/Source/Hosts/UI/MMCA.Store.UI.Web/appsettings.json:53-54.
Revision (2026-10-26)
Re-verified against current source. The decision is unchanged: both apps run the same-origin proxy,
the server is the only writer of the session cookies, and unsafe proxied methods require X-CSRF.
One long-standing omission is corrected, and the Program.cs and proxy-endpoint anchors moved.
- The CSRF bullet in the Decision now names the gate's one exemption: an HTTP/2 WebSocket extended
CONNECTcannot carry theX-CSRFheader, so it is admitted without it and relies on the proxy's same-origin gate, which requires this host's ownOriginon a WebSocket upgrade (MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/SameOriginProxy/SameOriginApiProxyEndpoint.cs:182-201,:265-266). - Anchors re-verified against current source:
MMCA.ADC/Source/Hosts/UI/MMCA.ADC.UI.Web/Program.cs:167andMMCA.Store/Source/Hosts/UI/MMCA.Store.UI.Web/Program.cs:159(AddCommonSameOriginApiProxy);SameOriginApiProxyEndpoint.cs:266(X-CSRFgate on unsafe methods).
Revision (2026-10-28)
Re-verified against current source. The decision is unchanged: both apps run the same-origin proxy,
the server is the only writer of the session cookies, and both apps configure
SameOriginApiProxy:SessionCookieSameSite as Lax. Only line numbers moved, in the consumer hosts
on v1.265.1.
- Anchors re-verified against current source:
MMCA.ADC/Source/Hosts/UI/MMCA.ADC.UI.Web/Program.cs:168andMMCA.Store/Source/Hosts/UI/MMCA.Store.UI.Web/Program.cs:160(AddCommonSameOriginApiProxy);MMCA.Store/Source/Hosts/UI/MMCA.Store.UI.Web/appsettings.json:65-66(SessionCookieSameSiteLax). Unchanged and re-confirmed:MMCA.ADC/Source/Hosts/UI/MMCA.ADC.UI.Web/appsettings.json:69-70.
Revision (2026-11-23)
Re-verified against current source. The decision is unchanged: both apps run the same-origin proxy,
the server is the only writer of the session cookies, /auth/session/token returns a claims-only
token and checks Sec-Fetch-Site, unsafe proxied methods require X-CSRF, and both apps configure
SessionCookieSameSite as Lax. Three omissions are corrected and the anchors moved.
- The token-issuing paths now name the fifth default,
auth/passkeys/signin(MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/SameOriginProxy/SameOriginApiProxySettings.cs:33). - The refresh bullet names the view-as overlay branch (ADR-137): a live overlay cookie is answered
first on
/auth/session/token, claims-only on the proxy, and never refreshed (MMCA.Common/Source/Presentation/MMCA.Common.API/SessionCookies/SessionCookieEndpoints.cs:80-85), and the circuit's token handoffPOST /auth/session/handoffalso answers a live overlay first and never refreshes it, but returns the view-as access token asSessionHandoffProtectorciphertext rather than a claims-only token (SessionHandoffEndpoints.cs:17,:33-36), which the Trade-offs now also name. - Neither host calls
AddCommonSameOriginApiProxydirectly any more:AddMmcaBlazorWebHostregisters it (MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/Hosting/BlazorWebHostExtensions.cs:142), called atMMCA.ADC/Source/Hosts/UI/MMCA.ADC.UI.Web/Program.cs:26andMMCA.Store/Source/Hosts/UI/MMCA.Store.UI.Web/Program.cs:30, andUseMmcaBlazorWebPipeline(:181) maps it throughMapCommonSameOriginApiProxy(:210), called at ADCProgram.cs:128and:130and StoreProgram.cs:92. - Anchors re-verified against current source:
SessionCookieEndpoints.cs:87and:97(token plus expiry),:94-96(SessionClaimsTokenunder claims-only),:110-112(IsCrossSite);SameOriginApiProxySettings.cs:116(SessionCookieSameSitedefaultStrict);SameOriginApiProxyEndpoint.cs:110(bearer taken from the session cookie),:273(X-CSRFgate with the WebSocket exemption),:146-152and:184-193(same-origin gate and WebSocket upgrade detection);SameOriginProxyTransformer.cs:77(bearer attached),:133and:256(token-issuing completion and cookie write);SessionHandoffEndpoints.cs:51(cookie handoffX-CSRFcheck) and:62(cookie write);MMCA.ADC/Source/Hosts/UI/MMCA.ADC.UI.Web/appsettings.json:86-87andMMCA.Store/Source/Hosts/UI/MMCA.Store.UI.Web/appsettings.json:64-65(SessionCookieSameSiteLax). Unchanged and re-confirmed:SessionCookieEndpoints.cs:41-55,:52,:56,:58-62,:69,:72;SameOriginApiProxyServiceExtensions.cs:24,:72,:73,:83-84;SessionHandoffEndpoints.cs:18,:26;SessionCookieAuthenticationHandler.cs:51,:55;SessionCookieSettings.cs:19.
Revision (2026-12-03)
MMCA.Common v1.331.0. The cookies, the SSR scheme, the proxy and the CSRF posture are unchanged. Sign-out
now reaches the server session: DELETE /auth/session-cookie ends the refresh session behind the cookie
through ICookieSessionEnder and the new anonymous POST auth/session/end before deleting the cookies,
and it and the cookie handoff expire a present view-as overlay (the new Decision bullet "Sign-out ends
the server session, not only the cookies";
MMCA.Common/Source/Presentation/MMCA.Common.API/SessionCookies/SessionCookieEndpoints.cs:49-71,
.../SessionCookies/CookieSessionEnder.cs:41-73,
.../Controllers/AuthControllerBase.cs:201-215,
MMCA.Common/Source/Core/MMCA.Common.Application/Auth/Sessions/AuthSessionIssuer.cs:222-244). The
end call is best effort with a 5-second budget; when it fails the cookies are deleted anyway and the
session lapses at its expiry. IAuthSessionIssuer gains SignOutByRefreshTokenAsync, a breaking
addition for an implementer.
The Decision's cookie bullets are also restated to match the source. No browser seed endpoint
exists and no claims-only switch exists: the server is the only writer of the cookies
(SessionCookieEndpoints.cs:16-18, ISessionCookieStore.cs:17), /auth/session/token always answers
a SessionClaimsToken (SessionCookieEndpoints.cs:105-107), and the proxy transformer and the cookie
handoff are the two write paths (SameOriginProxyTransformer.cs:258-260, SessionHandoffEndpoints.cs:73).
The CSRF bullet names the two cookie endpoints that exist, both refusing a cross-site request
(SessionCookieEndpoints.cs:51, :85), and every Decision and Trade-offs anchor is refreshed against
the carrier.
Related
ADR-004 (the JWT/JWKS validation the API performs on every call, which is why the SSR handler can skip signature validation), ADR-008 (the gateway and topology the UI talks to), ADR-019 (rate limiting on the auth surface), ADR-029 (the login brute-force protection this session seeds from), ADR-131 (the same-origin API proxy that extends this cookie to authenticate data calls and makes the server its only writer).