Repository navigation
Description
Summary
DBSC is registered over an existing cookie scheme, but once a session cookie exists, later authentication does not go back through the source scheme's per-request forwarding. When the source scheme's authenticate target can vary by request, for example through ForwardDefaultSelector, DBSC can establish a request user from a different target or partition than the one the source scheme would select for that request.
Related to #66478 (DBSC tracking), #68117 (API proposal), and the derived-scheme inheritance issues #69618 and #69619. The implementation was removed from .NET 11 by #69462 and backported by #69479, so this issue tracks a requirement for any future DBSC reintroduction rather than a .NET 11 servicing change.
What is wrong
- Registration calls
AuthenticateAsync(RegistrationSourceScheme). That call honors the source scheme's forwarding for the registration request, and DBSC mints refresh and session cookies from the resulting principal without recording which effective target produced it. - The generated DBSC policy scheme selects the session scheme based only on session-cookie presence. It does not re-evaluate the source scheme's
ForwardAuthenticate,ForwardDefaultSelector, orForwardDefaultfor the current request. - Refresh authenticates the refresh scheme and mints a new session cookie without checking the source scheme's current-request target.
PostConfigureDeviceBoundSessionAuthenticationOptionsredirects the application's default authenticate scheme to the DBSC policy scheme, so this substitution becomes the default authentication path.- DBSC accepts this composition without an error, and the API surface does not document that source schemes with request-dependent forwarding are unsupported.
Why it matters
- The invariant is that DBSC-derived authentication must resolve to the same effective source target as the wrapped scheme for the current request, or the unsupported composition must be rejected.
- Applications that partition cookie authentication per request, for example by selecting a partition-specific cookie scheme by host or path, cannot currently infer or enforce that requirement.
Affected code
Permalinks point to b3d5795c6f, the last main commit before the DBSC removal.
DeviceBoundSessionExtensions.cs:98-116- policy-scheme selector chooses the session scheme based only on cookie presence.DeviceBoundSessionHandler.cs:87-172- registration authenticates the source scheme through its forwarding, then mints derived cookies without binding the effective target.DeviceBoundSessionHandler.cs:174-276- refresh mints session cookies without checking the source scheme's current-request target.PostConfigureDeviceBoundSessionAuthenticationOptions.cs:25-39- default authenticate scheme redirected to the DBSC policy scheme.AuthenticationHandler.cs:204-221- forwarding resolution (ForwardAuthenticate, thenForwardDefaultSelector, thenForwardDefault) that DBSC's later-authentication path does not reproduce.Microsoft.AspNetCore.Authentication.DeviceBoundSessions0.11.0-rc.1.26425.128- experimental prerelease package containing the implementation.
Recommended fix
Selected approach: reject DBSC over source schemes whose authenticate target can vary by request.
- Add a source-scheme inspector that resolves the source scheme's forwarding configuration. Treat it as variable when
ForwardAuthenticateis unset andForwardDefaultSelectoris set. Follow staticForwardAuthenticateandForwardDefaultchains, and handle policy-scheme sources. - Prefer failing at startup through options validation with a clear message. Also enforce the check at runtime so an unsupported composition cannot mint or use derived cookies:
- Registration: do not authenticate the source scheme or mint refresh and session cookies.
- Policy scheme: do not select the session scheme; use the source scheme.
- Refresh: do not mint a session cookie.
- Document supported source-scheme compositions on
AddDeviceBoundSession.
A draft of the registration guard:
if (Options.RegistrationSourceScheme is { } sourceScheme &&
_sourceSchemeInspector.AuthenticateTargetCanVaryByForwarding(sourceScheme))
{
Logger.RegistrationUnsupportedSourceScheme(sourceScheme);
Response.StatusCode = StatusCodes.Status500InternalServerError;
return;
}Alternatives considered:
- Bind the resolved effective source target into protected refresh and session state at registration, then require the current request's source resolution to match it before the session scheme establishes a user and before refresh mints a session cookie. This supports the composition but adds per-request forwarding evaluation to the session path and more state to carry. It is a reasonable follow-up if forwarded sources should be supported.
- Document the limitation without enforcement. Rejected because callers cannot reliably detect whether a source scheme's target varies at runtime, and DBSC owns the substituted authentication decision.
Compatibility: no public API change is expected beyond documentation and possibly a validation error. Applications that currently compose DBSC over a request-dependent forwarding source will fail validation or stop receiving DBSC session authentication. Because the package is experimental and removed from .NET 11, apply this before any future DBSC package is published.
Acceptance criteria
- A source scheme whose authenticate target can vary by request is rejected with a clear error, or DBSC enforces that the current request's effective source target matches the target bound at registration.
- For an unsupported composition, registration mints no refresh or session cookies, the policy scheme does not select the session scheme, and refresh mints no session cookie.
- Sources without forwarding, and sources with a static forwarding chain, behave as they do today.
- Tests use the real
AddCookieandAddDeviceBoundSessionregistration path with a source scheme that usesForwardDefaultSelectorover two cookie schemes. They verify that a DBSC session established under one target does not authenticate a request that the source scheme resolves to the other target. -
AddDeviceBoundSessiondocumentation lists the supported source-scheme compositions. - Support Device Bound Session Credentials (DBSC) #66478 records this requirement before DBSC is reintroduced.
Activity