Architecture Decision Record
ADR-131: Same-Origin API Proxy (a Backend-for-Frontend That Keeps Tokens Out of Browser Script)
Status
Accepted (2026-10-01). Shipped in MMCA.Common v1.218.0. Revised 2026-10-06: v1.218.0 is released,
ADC adopted it through 1.218.1, HTTP/2 WebSocket CONNECT is exempt from the CSRF header, and proxied
hub traffic is exempt from the UI rate limiter.
Records the owner's TD-08 decision for Option A of the token-storage design note; the implementing
MMCA.Common commits are 4cfb4a35 (the proxy), b542dde1 (downloads through the proxy) and fba02c29
(refresh outcomes and the same-origin gate). Opt-in per host: a host that does not call
AddCommonSameOriginApiProxy is unchanged (MMCA.Common/UPGRADING.md:1696). Extends
ADR-022 (the HttpOnly session cookie, until now read only for
server-side rendering) and ADR-051 (the client token
lifecycle) without changing ADR-088 (the gateway stays the
API edge). Revised 2026-10-07: the proxied hub connection carries no X-CSRF header and both hub
modes are WebSocket-only with negotiation skipped, Unavailable covers every non-refusal status
including 409 Auth.RefreshSuperseded, and the implementing commits are on main as squash e9c28d15
(#469). Revised 2026-10-21: a seventh setting, MaxRequestBodySizeByPath (v1.237.0), raises the
request body cap per gateway-relative path before the session step, the validator also refuses
malformed endpoint paths and body-size entries, the proxy's switch-off of status-code pages for the
whole request (shipped in e9c28d15, so that a proxied empty-body 401 or 404 reaches the client
unchanged) is now recorded, the session cookie lifetime follows the refresh-token lifetime, and
anchors are refreshed. Revised 2026-10-26: the OPTIONS step and the ADR-082 link now say that no
preflight reaches the gateway while a forwarded request keeps the browser's Origin for the gateway's
CORS middleware, the session cookie is also Secure on any HTTPS request in Development (MMCA.Common
#588), and anchors are refreshed after MMCA.Common #587, #588, #590, #612 and the release notes through
v1.261.0. Revised 2026-10-28: anchors refreshed after MMCA.Common #615 (first tagged v1.262.0).
Revised 2026-11-23: passkey sign-in is a default token-issuing path, a token-issuing path opens a
session only on a 200 or 201 (a 202 registration passes through with no cookie), two settings join
(RevokeCurrentPath, treated like RevokePath, and ViewAsEndPath), the proxy carries the
ADR-137 view-as overlay cookie, the UI rate limiter
exempts no path by its file extension alone, two gate classes join, and anchors are refreshed
through MMCA.Common v1.315.0.
Context
A Blazor WebAssembly client calls the API through the gateway, which is a different origin from the
UI host, so the HttpOnly session cookies the UI host writes (ADR-022) never travel with those calls.
The client therefore authenticates with a bearer token script can read: a host that does not opt in
still attaches the stored token to the notification hub through
options.AccessTokenProvider = _tokenStorageService.GetAccessTokenAsync
(MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Notifications/NotificationHubService.cs:585;
off the browser the hub's own socket factory sets that bearer on the upgrade, :587-590, :631-635),
and to every "APIClient" call through AuthDelegatingHandler
(MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/AuthDelegatingHandler.cs:36). One
successful script injection can then lift a live token and use it from anywhere until it expires.
The ADC token-storage design note (kept in the private ADC repository) weighed four answers to "how
does an HttpOnly credential reach a cross-origin API": A, a same-origin proxy on the UI host; B, a
cookie scoped to a registrable domain shared by UI and API, sent straight to the gateway; C, keep the
script-readable token and shrink the blast radius (enforced CSP, short TTLs); and C+, an interim
hybrid with the refresh token in the HttpOnly cookie and the access token held in memory. C+ removes
the long-lived prize but still leaves a usable access token in script for its lifetime. The pieces A
needs already existed: the cookie pair and its writer (ISessionCookieStore,
MMCA.Common/Source/Presentation/MMCA.Common.API/SessionCookies/ISessionCookieStore.cs:15, HttpOnly,
Secure outside Development and on any HTTPS request in Development, SessionCookieJar.cs:69, with a
lifetime that defaults to Jwt:RefreshTokenExpirationDays when
that section is bound and to 7 days otherwise,
MMCA.Common/Source/Presentation/MMCA.Common.API/SessionCookies/SessionCookieSettings.cs:31-38,
resolved at SessionCookieJar.cs:35-47), and a single-flight refresher over that cookie
(ICookieSessionRefresher,
MMCA.Common/Source/Presentation/MMCA.Common.API/SessionCookies/CookieSessionRefresher.cs:31, striped
per refresh token, :68-72, :87).
Decision
The UI host serves the API on its own origin and forwards to the gateway server-side, attaching the bearer it reads from the HttpOnly cookie. The browser never holds a token that any API accepts.
- Opt-in, hosted in MMCA.Common.UI.Web.
AddCommonSameOriginApiProxy(IConfiguration)(MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/SameOriginProxy/SameOriginApiProxyServiceExtensions.cs:51) binds and validates the settings on start (:55-67), registers YARP's forwarder (:76) and data protection (:77), and replaces the Blazor Server circuit'sITokenRefresherandISessionCookieSyncwith protected-handoff implementations (:83-84).MapCommonSameOriginApiProxy()(MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/SameOriginProxy/SameOriginApiProxyEndpointExtensions.cs:33) maps{PathPrefix}/{**path}for every method, WebSocket upgrades included, anonymous by declaration, without antiforgery and outside the OpenAPI description (:49-52). It fails the boot when the registration call is missing (:38-42) or when a later registration displaced the handoff services, because that would put the access token back in the page (:59-69,:85-90). - Settings.
SameOriginApiProxySettings(MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/SameOriginProxy/SameOriginApiProxySettings.cs:22, sectionSameOriginApiProxy,:25):PathPrefix/api(:40),GatewayAddressdefaulting toApi:ApiEndpointso an Aspire discovery name resolves as it does for the host's other clients (:48, filled atSameOriginApiProxyServiceExtensions.cs:57-64), token-issuing pathsauth/login,auth/register,auth/oauth/exchange,auth/sign-in-link/redeem,auth/passkeys/signinplus anyAdditionalTokenIssuingPaths(:33,:54),MaxRequestBodySizeByPath(:56-77),RefreshPathauth/refresh(:84),RevokePathauth/revoke(:91),RevokeCurrentPathauth/revoke/current, the this-device sign-out, treated exactly likeRevokePath(:99,SameOriginApiProxyEndpoint.cs:330-335),ViewAsEndPathauth/view-as/end(:108) andSessionCookieSameSiteStrict(:116).MaxRequestBodySizeByPathis empty by default; each key is a gateway-relative path, matched case-insensitively on a whole-segment prefix with the longest key winning, and its value in bytes replaces the server default (Kestrel's is 30,000,000 bytes) for that path, so an upload the API accepts is not refused 413 at the UI host first. The validator refuses a prefix with route syntax, a non-absolute gateway and anySameSiteother thanStrictorLax(MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/SameOriginProxy/SameOriginApiProxySettingsValidator.cs:28-45), aRefreshPath,RevokePath,RevokeCurrentPath,ViewAsEndPathor additional token-issuing path that is not a non-empty relative path (:47-51), and aMaxRequestBodySizeByPathentry whose key is not such a path or whose limit is not positive (:53-66). - The request pipeline, in order.
SameOriginApiProxyEndpoint(MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/SameOriginProxy/SameOriginApiProxyEndpoint.cs:29) first disables the host's status-code pages for the request, so a proxied 401 or 404 with an empty body reaches the client as sent rather than as a re-executed HTML page (:75-80), then runs every gate before anything is forwarded (:82,:248-281):- Same-origin gate. An
Originthat is not exactly the host's own (scheme, host and port as the app sees them; a sibling subdomain is another origin), a WebSocket upgrade with noOrigin(HTTP/1.1 upgrade or HTTP/2 extendedCONNECT), or aSec-Fetch-Siteother thansame-originis refused 403cross_origin_rejected;noneis allowed only on a plain GET or HEAD, for a user-initiated navigation such as a pasted download link (:130-222, own-origin comparison:154-175, refusal:254-259). OPTIONSanswered locally with 204 and no CORS grant, never forwarded, so no preflight reaches the gateway on the proxy's behalf (:261-270). A request that clears the remaining steps and is forwarded keeps the browser'sOrigin, so the gateway's CORS middleware still sees it: the transformer starts from YARP's default header copy and never removesOrigin(SameOriginProxyTransformer.cs:70, its rewrites at:77-79).- CSRF header. Every unsafe method must carry exactly
X-CSRF: 1or gets 403csrf_header_required(:125-128,:272-278). The one exemption is a WebSocket opened over HTTP/2, an RFC 8441 extendedCONNECTto which a browser cannot add headers and which the same-origin gate has already held to the host's ownOrigin(:177-187,:273). The constants areSameOriginProxyHeaders(MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/SameOriginProxyHeaders.cs:11,:14,:17). - Body-size cap. When a
MaxRequestBodySizeByPathkey covers the gateway-relative path, the request's body limit is set to that value before anything reads the body (SameOriginApiProxyEndpoint.cs:89-90,:367-390, keys ordered longest first at:63-69). - Local refresh. A browser POST to the refresh path resolves to no forward mode and is answered
by the proxy itself, so nothing below runs for it (
SameOriginApiProxyEndpoint.cs:92-97; what it returns is under "What the forward rewrites"). - View-as overlay. A live
mmca_view_asoverlay cookie (MMCA.Common/Source/Presentation/MMCA.Common.API/SessionCookies/ViewAsOverlayCookie.cs:31, ADR-137) supplies the bearer for every request except a sign-in or a sign-out, and one that is present but no longer readable as live (expired or unreadable) is marked for deletion (SameOriginApiProxyEndpoint.cs:99,:397-419,:410,:417). - Session step. A request with a session cookie is validated or refreshed through
ICookieSessionRefresher.ValidateOrRefreshAsync; sign-in requests skip it so a stale session cannot block a login, and so does a request that forwards the overlay's bearer (SameOriginApiProxyEndpoint.cs:100-111). - Forward through YARP over HTTP/1.1 with a 100-second activity timeout, so an HTTP/1.1
WebSocket upgrade forwards as a plain upgrade and an HTTP/2 one is turned into an HTTP/1.1 GET
upgrade to the gateway (
:43-51,:424-434), with the bearer attached server-side. - One forced refresh and replay when a safe, bodiless method comes back 401 with the session's
bearer (a revoked token or a rotated key); nothing with a body, no upgrade and no view-as bearer
is re-sent (
:116-119,:228-237,:349-365).
- Same-origin gate. An
- What the forward rewrites.
SameOriginProxyTransformerreplaces any browserAuthorizationwith the request's bearer, drops theX-CSRFheader and strips the two session cookies and the view-as overlay cookie from the upstreamCookieheader (MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/SameOriginProxy/SameOriginProxyTransformer.cs:77-79, names at:58-59,:297-315). A token-issuing response that opens a session, a 200 or a 201, moves the pair into the cookies and reaches the browser withaccessTokenreplaced by its claims-only form andrefreshTokenemptied (:154-155,:237-260); any other success, such as a 202 for a registration that awaits confirmation, passes through unchanged with no cookie written andno-store(:133-148). A revoke forwards the bearer and clears the cookies whatever the upstream answered (:106-111). A view-as grant, a POST whose last segment isview-as, answered with a 2xx whoseaccessTokenis a readable JWT carrying both theact_subandvagclaims, moves that token into the overlay cookie and sends the claims-only form, leaving the session cookies alone (:118-121,:169-213,:267-286,SameOriginApiProxyEndpoint.cs:337-346); any other grant response, a non-2xx or a body whose token fails those checks, passes through unchanged, token included (SameOriginProxyTransformer.cs:124,:188,:205-207). A present overlay is deleted on a view-as end, a sign-out, a sign-in answered 200 or 201, an overlay that is no longer readable as live (expired or unreadable), or an upstream 401 to its bearer (:162-167,SameOriginApiProxyEndpoint.cs:410,:417); a 401 captured for the forced refresh and replay deletes nothing, since the transformer returns before that check and the replay runs with no overlay treatment (SameOriginProxyTransformer.cs:93-97,:101,SameOriginApiProxyEndpoint.cs:364,:421). A browser POST to the refresh path is answered by the proxy itself from the refresh cookie, with the claims-onlyaccessToken, an emptyrefreshTokenand theaccessTokenExpiry; under a live overlay it answers from the overlay's claims and expiry and rotates nothing (SameOriginApiProxyEndpoint.cs:92-97,:320-323,:436-476, overlay branch:443-458). - Stateless: tokens stay in the existing cookie. No server-side session store; the proxy reads and
writes the same HttpOnly pair through
ISessionCookieStore(ISessionCookieStore.cs:21,:25). - The browser holds an unsigned claims copy.
SessionClaimsToken.Create(MMCA.Common/Source/Presentation/MMCA.Common.API/SessionCookies/SessionClaimsToken.cs:25-33) keeps the access token's payload under an{"alg":"none","typ":"JWT"}header with an empty signature (:17), enough to render authentication state and nothing any API accepts (:7-13). Opting in setsSessionCookieSettings.ClaimsOnlyBrowserTokens, so/auth/session/tokenreturns the claims copy andPOST /auth/session-cookieignores script-supplied tokens (MMCA.Common/Source/Presentation/MMCA.Common.API/SessionCookies/SessionCookieSettings.cs:21-29, set atSameOriginApiProxyServiceExtensions.cs:69-74). - Refresh outcomes are three, not two.
SessionRefreshStatus(MMCA.Common/Source/Presentation/MMCA.Common.API/SessionCookies/SessionRefreshOutcome.cs:4) isRefreshed,Rejected(no refresh cookie, or the identity endpoint answered 400, 401 or 403) andUnavailable(any other status, a timeout, a network failure or an unreadable body) (:10-23), classified atCookieSessionRefresher.cs:122-125. "Any other status" covers 5xx, 429, 408, a 404 from a misrouted gateway, and 409Auth.RefreshSupersededwhen another request rotated the same token insideRefreshSessions:ReuseGraceSeconds(CookieSessionRefresher.cs:113-121). The proxy clears the cookies and answers 401 only onRejected; onUnavailableit keeps them, forwards and replays nothing, and answers 503 with the upstreamRetry-After, or 5 seconds when there is none (SameOriginApiProxyEndpoint.cs:54,:290-307). - The Blazor Server circuit trades handoffs, not tokens. The circuit keeps calling the gateway
server-to-server; it exchanges tokens with the cookies only as data-protected, purpose-bound
handoffs that live one minute
(
MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/SameOriginProxy/SessionHandoffProtector.cs:19,:21-27). - The WebAssembly client switches by configuration.
/client-configaddsSameOriginApiEndpointonly on an opted-in host (MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/ClientConfig/ClientConfigEndpointExtensions.cs:137-146), the bootstrap resolves it against the app base address (MMCA.Common/Source/Presentation/MMCA.Common.UI/Common/Settings/MmcaClientConfigBootstrap.cs:98), andApiSettings.SameOriginApiEndpoint(MMCA.Common/Source/Presentation/MMCA.Common.UI/Common/Settings/ApiSettings.cs:33) then becomes the"APIClient"base address (MMCA.Common/Source/Presentation/MMCA.Common.UI/DependencyInjection.cs:162) and addsSameOriginProxyRequestHandler(DependencyInjection.cs:175-181), which removes anyAuthorizationheader and stampsX-CSRF: 1(MMCA.Common/Source/Presentation/MMCA.Common.UI/Services/Auth/SameOriginProxyRequestHandler.cs:11,:18-20). - Hubs are proxied too. On an opted-in client the notification hub connects through the proxy
with no token, no extra header and no access-token provider (
NotificationHubService.cs:106-107,:112-116,:580-583). A browser cannot add headers to a WebSocket upgrade, so the proxy needs noX-CSRFthere: a GET upgrade is a safe method and an HTTP/2 extendedCONNECTis exempt (SameOriginApiProxyEndpoint.cs:273), and both are held to the host's ownOriginby the same-origin gate (:195-203); the proxy attaches the bearer to the upgrade server-side. Both modes skip negotiation and use WebSockets only, with no Server-Sent Events or long-polling fallback (NotificationHubService.cs:577-578). - Downloads follow the API client.
ApiFileDownloadButtonresolves its anchor base asSameOriginApiEndpoint, thenWasmApiEndpoint, thenApiEndpoint(MMCA.Common/Source/Presentation/MMCA.Common.UI/Components/Forms/ApiFileDownloadButton.razor.cs:127), so a top-level GET carries the cookie and the proxy supplies the bearer. - MAUI is excluded. Native heads keep OS SecureStorage and talk to the gateway directly; the
"APIClient"pipeline changes only whenSameOriginApiEndpointis configured, which only an opted-in host's WebAssembly client receives (DependencyInjection.cs:143-147). - SameSite: Strict by default, Lax allowed. The framework-wide cookie default stays
Lax(SessionCookieSettings.cs:19); opting in raises it to the proxy'sSessionCookieSameSite,Strictunless the host choosesLax(SameOriginApiProxySettings.cs:110-116). CSRF protection rests on the header and origin gates above, not onSameSite. MMCA.ADC, which adopted the proxy with MMCA.Common 1.218.1 (ADC #236), setsLaxso a signed-in user arriving from a mailed deep link keeps the session on the first server render, and raises the body cap forSessionAssets/fileto 52,494,336 bytes so session-material uploads the gateway and API accept are not refused at the UI host (MMCA.ADC/Source/Hosts/UI/MMCA.ADC.UI.Web/appsettings.json:77-91, the two settings at:87,:88-90). - Gates. The behavior is pinned by
SameOriginApiProxyOptInTests(hosts that do not opt in are unchanged,MMCA.Common/Tests/Presentation/MMCA.Common.UI.Web.Tests/SameOriginProxy/SameOriginApiProxyOptInTests.cs:21),SameOriginApiProxyCsrfTests(SameOriginApiProxyCsrfTests.cs:12),SameOriginApiProxyOriginTests(SameOriginApiProxyOriginTests.cs:14),SameOriginApiProxyRefreshOutcomeTests(SameOriginApiProxyRefreshOutcomeTests.cs:14),SameOriginApiProxyHubTests(SameOriginApiProxyHubTests.cs:29),SameOriginApiProxyTokenTests(SameOriginApiProxyTokenTests.cs:15),SameOriginApiProxyAuthFlowTests(SameOriginApiProxyAuthFlowTests.cs:19),SameOriginApiProxyBodySizeTests(SameOriginApiProxyBodySizeTests.cs:40),SameOriginApiProxyRegistrationTests(SameOriginApiProxyRegistrationTests.cs:15),SameOriginApiProxyViewAsTests(SameOriginApiProxyViewAsTests.cs:15) andSessionHandoffServicesTests(SessionHandoffServicesTests.cs:14), all in the same folder.
Rationale
- Tokens out of script, with no infrastructure prerequisite. An injected script can still call the
API as the user while the page is open, but it cannot carry a token away: the only token in script
is the unsigned claims copy (
SessionClaimsToken.cs:7-13). Option B buys the same property only once UI and API share a registrable domain in every environment. - Reuse, not a second auth system. The proxy is built on the cookie writer and the single-flight
refresher that already served server-side rendering (
ISessionCookieStore.cs:15,CookieSessionRefresher.cs:68-72), so there is one place a session is refreshed and one cookie format. - The right package. MMCA.Common.UI.Web is server-only; the MMCA.Common.UI Razor class library is loaded by WebAssembly and MAUI heads, which cannot host a forwarder, and MMCA.Common.API is referenced by every service, which would carry a YARP dependency into hosts that never front a browser.
- Defense in depth for CSRF. A cookie that authenticates data calls must not be usable from
another origin. The custom header cannot be sent cross-origin without a preflight, and the proxy
never answers a preflight with a grant (
SameOriginApiProxyEndpoint.cs:261-270); the origin gate covers what the header cannot, a WebSocket upgrade, which is not CORS-protected (:137-139). Both gates were added after an adversarial review found upgrades and preflights open (commit fba02c29, which reachedmainin the squash commit e9c28d15, #469). - A blip at the identity endpoint must not sign users out. Treating every failed refresh as the
end of the session cleared the cookies on a 5xx or a timeout; separating
UnavailablefromRejectedkeeps a live session and tells the client when to retry (SessionRefreshOutcome.cs:12-23). - SameSite is a usability choice, not the CSRF control. Because the header and origin gates carry
CSRF, a consumer can choose
Laxfor deep links without weakening the data path;Nonestays impossible (SameOriginApiProxySettingsValidator.cs:42-45).
Trade-offs
- One extra hop. Every browser API call and every hub frame passes through the UI host before the
gateway (
SameOriginApiProxyEndpoint.cs:424-434). - The UI host becomes a stateful-ish auth edge. It owns refresh, the refresh race, the 401 replay
and cookie rotation for browser traffic (
SameOriginApiProxyEndpoint.cs:349-365,:436-476); a UI host outage now takes the browser's API path down with it. - Upload limits are the UI host's too. Every proxied body passes through the UI host, so an
upload larger than its server default is refused 413 there unless the host maps that path in
MaxRequestBodySizeByPath(SameOriginApiProxySettings.cs:56-77); a consumer that raises a limit at the gateway or the API raises it here as well. - The UI host rate limiter now meters API traffic. Its exempt prefixes are
/health,/alive,/_framework,/_contentand/hubs(MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/Hardening/UiRateLimitingExtensions.cs:80), and proxied hub traffic under{PathPrefix}/hubs(the hub at/api/hubs/notifications,NotificationHubService.cs:109) is exempt too (UiRateLimitingExtensions.cs:75-78,:104). Beyond those prefixes only a request routed to a real static asset in the static-asset manifest is exempt; no path is exempt by its file extension alone (:89-92). Every other proxied/api/**call counts against the per-IP window and the concurrency ceiling of ADR-124 (UiRateLimitingExtensions.cs:102-104,:122-128, the chained limiters at:254). - Ingress hosts must adopt forwarded headers or lose every POST. The origin gate compares against
the scheme, host and port as the app sees them (
SameOriginApiProxyEndpoint.cs:154-175), so a host behind a TLS-terminating ingress must callUseCommonUiForwardedHeaders()(MMCA.Common/Source/Presentation/MMCA.Common.API/Startup/CommonForwardedHeadersExtensions.cs:24) first, or every browser POST is refused (UPGRADING.md:1685-1689). - Registration order matters.
AddCommonSameOriginApiProxymust come after everyITokenRefresherandISessionCookieSyncregistration; the boot fails otherwise (SameOriginApiProxyServiceExtensions.cs:29-35). - Client code that presented the browser-held token breaks. Decoding it for claims still works;
sending it to the gateway does not (
UPGRADING.md:1690-1691), and requests a host writes by hand must addX-CSRF: 1on unsafe methods (UPGRADING.md:1683-1685). - Script on the page can still act as the user. The proxy removes theft, not use: an injected script runs same-origin and passes both gates. Content Security Policy (ADR-023) stays the control for that.
Alternatives rejected
- Option B: a same-site cookie sent straight to the API (weighed 2026-10-01). Rejected because it needs UI and gateway under one registrable domain in every environment (DNS, certificates, infrastructure), a cookie-JWT path in every service, and credentialed gateway CORS. Revisit if production puts UI and API under one parent domain for other reasons.
- Stopping at the C+ hybrid (weighed 2026-10-01). Rejected because the access token stays in script for its lifetime, so theft is shortened rather than removed. C+ was the interim step, not the target.
- A server-side session store (rejected 2026-10-01). Holding tokens in a store keyed by an opaque session id would make every UI host depend on a stateful store and its availability; the existing HttpOnly cookie already keeps the tokens out of script, so the proxy stays stateless. Revisit if token size outgrows a cookie or server-side revocation of a browser session becomes a requirement.
- Hosting the proxy in MMCA.Common.UI or MMCA.Common.API (rejected 2026-10-01). The Razor class library is loaded by WebAssembly and MAUI heads, and the API package by every service, which would push YARP into hosts that front no browser.
SameSiteor an antiforgery token as the CSRF control (rejected 2026-10-01).SameSite=Laxmust remain available for deep links, and the API client is not a form post; the fixed header plus the origin gate cover both fetches and WebSocket upgrades.- Forwarding
OPTIONSto the gateway (rejected 2026-10-01, after review). The gateway's CORS policy would then decide whetherX-CSRFmay be sent cross-origin to the proxy (SameOriginApiProxyEndpoint.cs:261-264). - Proxying MAUI too (rejected 2026-10-01). A native head has no DOM and no script-injection surface, keeps tokens in OS SecureStorage, and would only gain a hop.
Consequences
- Adoption, per Blazor Web host. Register after the session-cookie and token registrations, map
next to the session-cookie endpoints after
UseAuthorization, configure the section only where a default does not fit, and callUseCommonUiForwardedHeaders()first behind an ingress (UPGRADING.md:1665-1696). - The gateway URL stays configured.
ApiEndpointkeeps the gateway address for full-page navigations that must reach the gateway itself, such as the external sign-in challenge (ApiSettings.cs:25-31). - What to watch. UI host 429s and concurrency rejections on
/api/**after a consumer opts in (the limiter above now sees API traffic; proxied hub traffic stays exempt), 503session_refresh_unavailablerates as a signal of identity-endpoint health (read alongside the 409Auth.RefreshSupersededrotation races it also counts, from a second tab or another replica insideRefreshSessions:ReuseGraceSeconds), and 403cross_origin_rejectedspikes after an ingress change, which usually mean forwarded headers are missing.
Revision (2026-10-06)
- Release state. MMCA.Common v1.218.0 is released (tags
v1.218.0andv1.218.1), and MMCA.ADC adopted the proxy with 1.218.1 (ADC #236); the Status line and the SameSite bullet no longer describe an unreleased version or an unmerged adoption branch. - CSRF exemption for HTTP/2 WebSockets. An RFC 8441 extended
CONNECTwith:protocol websocketis exempt from theX-CSRFheader and still held to the host's ownOrigin(SameOriginApiProxyEndpoint.cs:169-172,:251); YARP turns it into an HTTP/1.1 GET upgrade upstream (:40-48). - Rate limiter and hub traffic. Proxied hub traffic under
{PathPrefix}/hubsis exempt from the UI host limiter, while non-hub proxied paths count even with a file extension (UiRateLimitingExtensions.cs:51-56,:65-70); the Trade-offs and Consequences text no longer says the hub is metered. - Every
path:lineanchor in the live sections was re-verified against current source and moved where the code had moved.
Revision (2026-10-07)
Re-verified against current source. The proxy's own code, its gates and its settings are unchanged.
MMCA.Common v1.233.0 (#520, commit b222df4f) changed the hub transport, and it added
RefreshSessionSettings.ReuseGraceSeconds (section RefreshSessions, default 10,
MMCA.Common/Source/Core/MMCA.Common.Application/Auth/RefreshSessionSettings.cs:12, :98) with a new
identity-endpoint answer, 409 Auth.RefreshSuperseded for a rotation inside that window
(MMCA.Common/Source/Core/MMCA.Common.Application/Auth/Sessions/AuthSessionIssuer.cs:276-280, :330,
:438). The proxy's unchanged ClassifyFailure routes that answer to Unavailable, a 503 with
Retry-After (CookieSessionRefresher.cs:122-125, :195-197), so the refresh behavior the browser
sees changed, and the hub, refresh and What-to-watch text moved.
- The proxied hub sends no CSRF header. The Decision bullet no longer says the hub connects with
the
X-CSRFheader: it connects with no token and no extra header (NotificationHubService.cs:518-521,:540-543), and the proxy lets the upgrade through because a GET upgrade is a safe method and an HTTP/2 extendedCONNECTis exempt (SameOriginApiProxyEndpoint.cs:251), both held to the host's ownOrigin(:175-188). - WebSocket-only hub transport. Both modes skip negotiation and use WebSockets only, with no
Server-Sent Events or long-polling fallback (
NotificationHubService.cs:537-538). Off the browser, the direct connection's socket factory sets the stored bearer on the upgrade (NotificationHubService.cs:547-550,:590-594); the Context paragraph now says so. Unavailablecovers every non-refusal status. The Decision bullet now names 408, a misrouted 404 and 409Auth.RefreshSupersededinsideRefreshSessions:ReuseGraceSecondsalongside 5xx and 429 (CookieSessionRefresher.cs:113-125).- Implementing commits. 4cfb4a35, b542dde1 and fba02c29 are on the feature branch only; the work
reached
mainas the squash commit e9c28d15 (#469), contained in tagv1.218.0. The Rationale citation now names it. - Anchors re-verified against current source:
NotificationHubService.cs:528->:545;NotificationHubService.cs:97->:100-102(Decision and Trade-offs);:522-526->:540-543;CookieSessionRefresher.cs:119-121->:122-125. The other live anchors still hold.
Revision (2026-10-21)
Re-verified against current source. The gates, their order, the refresh outcomes, the claims-only browser token, the WebAssembly switch and the release provenance are unchanged. MMCA.Common v1.237.0 (#541, commit 87758096) added a seventh setting and moved most anchors in the endpoint and settings files; the session cookie lifetime is no longer a fixed 7 days.
MaxRequestBodySizeByPath. A new setting maps gateway-relative paths to request body limits in bytes (case-insensitive, whole-segment prefix, longest key wins, replacing Kestrel's 30,000,000-byte default;MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/SameOriginProxy/SameOriginApiProxySettings.cs:55-76). The endpoint applies it after the gates and before the session step (SameOriginApiProxyEndpoint.cs:86-87,:344-367). The Settings bullet, the pipeline list (new step 4), the SameSite bullet (MMCA.ADC raisesSessionAssets/file,MMCA.ADC/Source/Hosts/UI/MMCA.ADC.UI.Web/appsettings.json:71-73) and the Trade-offs now say so.- Validator. Besides the prefix, gateway and
SameSitechecks (SameOriginApiProxySettingsValidator.cs:28-45), it refuses a malformedRefreshPath,RevokePathor additional token-issuing path (:47-51) and an invalidMaxRequestBodySizeByPathkey or non-positive limit (:53-66). - Status-code pages disabled. The endpoint turns the host's status-code pages off for the
request before the gates, so a proxied empty-bodied 401 or 404 is not re-executed as an HTML page
(
SameOriginApiProxyEndpoint.cs:72-77); the pipeline lead now says so. - Local refresh answer. The refresh-path answer carries the claims-only
accessToken, an emptyrefreshTokenandaccessTokenExpiry(SameOriginApiProxyEndpoint.cs:404-411); the Decision bullet names those fields instead of calling it the same shape as a forwarded sign-in response. - Cookie lifetime.
SessionCookieSettings.Lifetimedefaults toJwt:RefreshTokenExpirationDayswhen bound and otherwise 7 days (MMCA.Common/Source/Presentation/MMCA.Common.API/SessionCookies/SessionCookieSettings.cs:31-38,SessionCookieJar.cs:35-47); the Context paragraph no longer says 7-day. - Gates.
SameOriginApiProxyBodySizeTests(SameOriginApiProxyBodySizeTests.cs:40) andSessionHandoffServicesTests(SessionHandoffServicesTests.cs:14) join the listed gate classes. - Anchors re-verified against current source:
AuthDelegatingHandler.cs:14->:15;CookieSessionRefresher.cs:67-71,:87->:68-73,:88;:122-125->:123-126;:113-121->:114-122;SameOriginApiProxySettings.cs:21,:24,:31,:38,:46,:52,:59,:66,:74,:68-74->:22,:25,:32,:39,:47,:53,:83,:90,:98,:92-98;SameOriginApiProxySettingsValidator.cs:26-43,:40-43->:28-45,:42-45;SameOriginApiProxyEndpoint.cs:71,:232-259->:79,:241-272;:115-207->:128-220;:146-160and:139-160->:152-173;:234-239->:247-252;:241-248->:254-261;:241-242->:254-255;:110-113,:250-256->:123-126,:263-269;:169-172,:251->:175-185,:264;:175-188->:193-201;:122-124->:135-137;:85-96->:96-109;:339-349->:377-387;:339-342->:377-380;:98-104,:213-217,:313-329->:111-117,:226-230,:326-342;:76-81,:291-301,:351-374->:89-94,:300-324,:389-412;:268-285->:281-298;DependencyInjection.cs:136,:153-154,:117-121->:144,:161-162,:125-129;appsettings.json:60-65->:60-74;UPGRADING.md:243-274,:261-263,:264-267,:268-269->:659-690,:677-679,:679-683,:684-685(the Status paragraph'sUPGRADING.md:274is now:690). The other live anchors still hold.
Revision (2026-10-26)
Re-verified against current source. The gates, their order, the refresh outcomes, the claims-only
browser token, the hub transport, the rate-limiter exemptions and the proxy settings are unchanged.
MMCA.Common #587 (commit 51c321fe) rewrote the comment above the OPTIONS answer, shifting the endpoint
anchors after it by two; #588 (commit e450a762) changed the session cookie's Secure flag; #590
(commit 622633f3) moved the rate-limiter anchors; #612 (commit 1c481e69) moved the hub anchors; and the
release notes added since, through v1.261.0 (#613), moved the UPGRADING.md anchors.
OPTIONSand the gateway's CORS policy.OPTIONSis still answered locally with 204 and never forwarded, so no preflight reaches the gateway (SameOriginApiProxyEndpoint.cs:254-263). A request that clears the remaining steps and is forwarded keeps the browser'sOrigin, because the transformer starts from YARP's default header copy and never removesOrigin(SameOriginProxyTransformer.cs:53); it replaces or nullsAuthorization, removesX-CSRFand strips the session cookies (:60-62). So the gateway's CORS middleware still sees those requests. Decision step 2 and the ADR-082 entry in Related no longer say the gateway's CORS policy is never consulted.- Adoption pointer. The
UPGRADING.mdopt-in steps sit at:887-918. Step 3 there (:898-901) lists the settings a host may configure withoutMaxRequestBodySizeByPath; the Settings bullet above remains the reference for that seventh setting. - Session cookie
Secureflag. The cookie isSecureoutside Development and, in Development, on any HTTPS request, so only a plainhttp://localhostrun goes without it (MMCA.Common/Source/Presentation/MMCA.Common.API/SessionCookies/SessionCookieJar.cs:68,ISessionCookieStore.cs:9); the Context paragraph now says so. - Anchors re-verified against current source:
SameOriginApiProxyEndpoint.cs:241-272->:241-274;:254-261->:254-263;:263-269,:264->:265-271,:266;:344-367->:346-369;:377-387,:377-380->:379-389,:379-382;:326-342->:328-344;:300-324->:302-326;:389-412->:391-414;:281-298->:283-300;ISessionCookieStore.cs:14,:20,:24->:15,:21,:25;NotificationHubService.cs:545->:546;:547-550,:590-594->:548-551,:591-595;:100-102->:100-101(endpoint selection) and:103(the/hubs/notificationsURL);:518-521,:540-543,:537-538->:519-522,:541-544,:538-539;UiRateLimitingExtensions.cs:56->:78;:51-54->:73-76,:107;:65-70->:104-116(carve-out:112-115);UPGRADING.md:274->:918;:659-690->:887-918;:677-679,:679-683,:684-685->:906-907,:907-911,:912-913. Anchors inside the dated revisions above stay as written. The other live anchors still hold.
Revision (2026-10-28)
Re-verified against current source. The gates, their order, the refresh outcomes, the session cookie
flags and lifetime, the proxy settings and the UPGRADING.md anchors are unchanged. MMCA.Common #615
(commit 0d40fff3, first tagged v1.262.0) rewrote the comment above the session cookie options, which
moved the Secure anchor by one line.
Secureflag scope. The cookie dropsSecurefor any plain-http request in Development, whatever the host name (Secure = !environment.IsDevelopment() || context.Request.IsHttps,MMCA.Common/Source/Presentation/MMCA.Common.API/SessionCookies/SessionCookieJar.cs:69); the 2026-10-26 item 3 wording "only a plainhttp://localhostrun" names the common case, not the rule. The Context paragraph already states the rule.- Anchors re-verified against current source:
SessionCookieJar.cs:68->:69(Context);SessionCookieJar.cs:35-47still holds. Anchors inside the dated revisions above stay as written (RefreshSessionSettings.cs:98is now:99). The other live anchors still hold.
Revision (2026-11-23)
Re-verified against current source (MMCA.Common v1.315.0). The gates, their order, the refresh
outcomes, the claims-only browser token, the hub transport, the rate limiter's exempt prefixes and
the SameSite rules are unchanged. Since the last revision the proxy gained passkey sign-in as a
default token-issuing path, a this-device sign-out path, the view-as overlay of
ADR-137 and a pass-through for a token-issuing success that
opens no session, and the UI rate limiter dropped its file-extension exemption. Two existing
behaviors changed for an opted-in host: a token-issuing 2xx other than 200 or 201 no longer writes
the cookies even when it carries a token pair (item 2), and a POST to auth/revoke/current, once a
plain forward, now clears the session cookies (item 3). A host that does not opt in is unchanged.
- Passkey sign-in issues a session.
DefaultTokenIssuingPathsnow has a fifth entry,auth/passkeys/signin(MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/SameOriginProxy/SameOriginApiProxySettings.cs:27-33); the Settings bullet names it. - Only a 200 or 201 opens a session. On a token-issuing path the transformer moves the pair into
the cookies only for a 200 or a 201; any other success, such as a 202 for a registration that
awaits confirmation, is copied through with no cookie and
no-store(SameOriginProxyTransformer.cs:133-148,:154-155). The transformer bullet now says so, andSameOriginApiProxyRegistrationTests(SameOriginApiProxyRegistrationTests.cs:15) joins the gate classes. - Two new settings, nine in all.
RevokeCurrentPath(auth/revoke/current,SameOriginApiProxySettings.cs:99) is treated exactly likeRevokePath(SameOriginApiProxyEndpoint.cs:330-335), andViewAsEndPath(auth/view-as/end,SameOriginApiProxySettings.cs:108) ends a view-as session; the validator checks both (SameOriginApiProxySettingsValidator.cs:47-51). TheUPGRADING.mdopt-in step 3 (:1676-1679) still lists neither, norMaxRequestBodySizeByPath; the Settings bullet remains the reference. - View-as overlay. A live
mmca_view_ascookie (MMCA.Common/Source/Presentation/MMCA.Common.API/SessionCookies/ViewAsOverlayCookie.cs:31) supplies the forwarded bearer except on a sign-in or sign-out, and the session step is skipped when it does (SameOriginApiProxyEndpoint.cs:99-100,:397-419); a view-as bearer is never refreshed or replayed (:236-237). A POST whose last segment isview-asis a grant; on a 2xx whoseaccessTokenis a JWT carrying bothact_subandvagthe token moves into the overlay cookie with the session cookies untouched, and any other grant response passes through unchanged, token included (SameOriginApiProxyEndpoint.cs:337-346,SameOriginProxyTransformer.cs:31,:118-121,:169-213,:267-286); a present overlay is deleted on a view-as end, a sign-out, a sign-in answered 200 or 201, an overlay no longer readable as live, or an upstream 401 to its bearer, but not on a 401 captured for replay (SameOriginProxyTransformer.cs:34,:93-101,:162-167,SameOriginApiProxyEndpoint.cs:410,:417,:421); the overlay cookie is stripped from the upstreamCookieheader with the session pair (:58-59,:306); and the local refresh answer under a live overlay returns the overlay's claims and expiry and rotates nothing (SameOriginApiProxyEndpoint.cs:443-458). The pipeline gains the overlay step, andSameOriginApiProxyViewAsTests(SameOriginApiProxyViewAsTests.cs:15) joins the gate classes. - No file-extension exemption from the UI rate limiter. MMCA.Common #793 (commit 17b34b20,
v1.313.0) replaced the rule that exempted any extension path outside the proxy prefix with one
that exempts only a request routed to a real static asset
(
MMCA.Common/Source/Presentation/MMCA.Common.UI.Web/Hardening/UiRateLimitingExtensions.cs:89-92,:122-128); the Trade-offs bullet now says so, and drops the proxy-prefix carve-out it no longer needs. - The pipeline lists the local refresh. A POST to the refresh path is answered after the
body-size cap and before the overlay step (
SameOriginApiProxyEndpoint.cs:92-97), now step 5 of the pipeline; the steps after it are renumbered. - Anchors re-verified against current source:
SameOriginApiProxySettings.cs:32,:39,:47,:53,:55-76,:83,:90,:98,:92-98->:33,:40,:48,:54,:56-77,:84,:91,:116,:110-116;SameOriginApiProxyEndpoint.cs:72-77,:79,:241-274->:75-80,:82,:248-281;:128-220,:152-173,:247-252->:130-222,:154-175,:254-259;:254-263,:254-255->:261-270,:261-264;:123-126,:265-271,:266->:125-128,:272-278,:273;:175-185->:177-187;:193-201->:195-203;:135-137->:137-139;:86-87,:346-369,:60-66->:89-90,:367-390,:63-69;:96-109->:100-111;:40-48,:379-389,:379-382->:43-51,:424-434;:111-117,:226-230,:328-344->:116-119,:228-237,:349-365;:89-94,:302-326,:391-414->:92-97,:320-323,:436-476;:51,:283-300->:54,:290-307;SameOriginProxyTransformer.cs:53,:60-62,:156-172,:91,:134-143,:84-87->:70,:77-79,:297-315,:154-155,:237-260,:106-111;CookieSessionRefresher.cs:32,:68-73,:88,:123-126,:114-122->:31,:68-72,:87,:122-125,:113-121;NotificationHubService.cs:546,:548-551,:591-595->:585,:587-590,:631-635;:100-101,:519-522,:541-544,:538-539,:103->:106-107,:112-116,:580-583,:577-578,:109;UiRateLimitingExtensions.cs:78,:73-76,:107,:104-116,:112-115->:80,:75-78,:104,:102-104and:122-128(chained limiters:254);appsettings.json:60-74,:70,:71-73->:77-91,:87,:88-90;UPGRADING.md:918,:887-918,:906-907,:907-911,:912-913->:1696,:1665-1696,:1683-1685,:1685-1689,:1690-1691;ClientConfigEndpointExtensions.cs:99->:137-146;DependencyInjection.cs:144,:161-162,:125-129->:162,:175-181,:143-147;ApiFileDownloadButton.razor.cs:98->:127;AuthDelegatingHandler.cs:15->:36;SameOriginApiProxyAuthFlowTests.cs:20->:19. Anchors inside the dated revisions above stay as written. The other live anchors still hold.
Related
ADR-022 (the HttpOnly session cookie the proxy reads),
ADR-051 (client token lifecycle across render modes),
ADR-023 (security headers and the CSP),
ADR-082 (the gateway CORS posture, which never sees a proxied preflight
but still sees the browser's Origin on every forwarded request),
ADR-088 and
ADR-089 (the gateway behind the proxy),
ADR-124 (the UI host as its own hardened edge),
ADR-070 (startup validation of the proxy settings).
Framework version and package figures live in MMCA.Common/FACTS.md.