Repository navigation
Avoid simple requests for SignalR authentication refresh - #70452
Conversation
Co-authored-by: Copilot <[email protected]> Copilot-Session: fdac132c-0926-4fda-8c97-88ae5b59b9fd
There was a problem hiding this comment.
🟡 Changes recommended
Removing the slow authorization policy and gate breaks an existing server regression test, while SignalR has unresolved issues with 404 guidance and shutdown cancellation during refresh.
3 open issues
What changed in this PR
This PR updates SignalR authentication refresh to use a connection-token header and adds challenge-driven refresh to the TypeScript and .NET long-polling clients.
Changes:
- Require
X-SignalR-Connection-Tokenfor refresh requests and introduce an explicit long-polling refresh challenge, with a legacy compatibility switch. - Update clients to handle refresh challenges and preserve HTTP error handling.
- Expand protocol documentation, client/server tests, and Blazor browser coverage.
| File | Description |
|---|---|
| src/SignalR/docs/specs/TransportProtocols.md | Documents the refresh endpoint and token header. |
| src/SignalR/common/Http.Connections/test/MapConnectionHandlerTests.cs | Checks CORS metadata on the refresh endpoint. |
| src/SignalR/common/Http.Connections/test/HttpConnectionDispatcherTests.AuthenticationRefresh.cs | Tests header requirements, challenges, and legacy behavior. |
| src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.cs | Requires the token header and issues refresh challenges. |
| src/SignalR/common/Http.Connections/src/HttpConnectionDispatcherOptions.cs | Adds the legacy long-polling compatibility switch. |
| src/SignalR/clients/ts/signalr/tests/Utils.SendMessage.test.ts | Tests send-response status handling. |
| src/SignalR/clients/ts/signalr/tests/OutputSize.test.ts | Raises the minified bundle size limit. |
| src/SignalR/clients/ts/signalr/tests/LongPollingTransport.test.ts | Covers refresh challenges, failures, and DELETE responses. |
| src/SignalR/clients/ts/signalr/tests/HttpConnection.test.ts | Updates refresh URL and header assertions. |
| src/SignalR/clients/ts/signalr/tests/HttpConnection.Negotiate.test.ts | Tests negotiation error details and guidance. |
| src/SignalR/clients/ts/signalr/tests/HttpConnection.AuthenticationRefresh.test.ts | Tests refresh callback wiring and poll retry. |
| src/SignalR/clients/ts/signalr/tests/FetchHttpClient.test.ts | Tests returned non-success HTTP responses. |
| src/SignalR/clients/ts/signalr/src/XhrHttpClient.ts | Returns completed responses regardless of status. |
| src/SignalR/clients/ts/signalr/src/Utils.ts | Adds status helpers and send-error handling. |
| src/SignalR/clients/ts/signalr/src/LongPollingTransport.ts | Handles refresh challenges and DELETE status codes. |
| src/SignalR/clients/ts/signalr/src/HttpConnection.ts | Sends the token header and wires transport refresh. |
| src/SignalR/clients/ts/signalr/src/HttpClient.ts | Documents completed-response semantics. |
| src/SignalR/clients/ts/signalr/src/HeaderNames.ts | Defines the connection-token header name. |
| src/SignalR/clients/ts/signalr/src/FetchHttpClient.ts | Returns non-success responses for caller handling. |
| src/SignalR/clients/csharp/Http.Connections.Client/src/Internal/LongPollingTransport.cs | Handles refresh challenges and disposes poll responses. |
| src/SignalR/clients/csharp/Http.Connections.Client/src/Internal/DefaultTransportFactory.cs | Passes the refresh callback to long polling. |
| src/SignalR/clients/csharp/Http.Connections.Client/src/Internal/Constants.cs | Defines the connection-token header name. |
| src/SignalR/clients/csharp/Http.Connections.Client/src/HttpConnection.cs | Sends the token header and supplies the refresh callback. |
| src/SignalR/clients/csharp/Client/test/UnitTests/LongPollingTransportTests.cs | Tests challenge retries and failure handling. |
| src/SignalR/clients/csharp/Client/test/UnitTests/HttpConnectionTests.AuthenticationRefresh.cs | Tests refresh wiring, URLs, and headers. |
| src/Components/test/testassets/Components.TestServer/Pages/_ServerHost.cshtml | Adds query-selected long-polling test configuration. |
| src/Components/test/testassets/Components.TestServer/AuthenticationStartup.cs | Adds a long-polling endpoint; removes authorization-gate setup. |
| src/Components/test/testassets/BasicTestApp/AuthTest/AuthorizeViewCases.razor | Adds an interactivity counter for browser assertions. |
| src/Components/test/E2ETest/ServerExecutionTests/ServerAuthTest.cs | Tests authentication changes while preserving connection and interactivity. |
Review effort: Balanced
| var authorizationGate = new BasicTestApp.AuthTest.AsyncAuthorizationGate(); | ||
| services.AddSingleton(authorizationGate); | ||
|
|
||
| services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(); |
| const response = await this._httpClient.post(negotiateUrl, request); | ||
|
|
||
| if (response.statusCode !== 200) { | ||
| if (response.statusText || (typeof response.content === "string" && response.content)) { |
| && this._isAuthenticationRefreshRequired(response)) { | ||
| authenticationRefreshAttempted = true; | ||
| try { | ||
| await this._authenticationRefresh(); |
|
/review |
There was a problem hiding this comment.
Source-only review of frozen head a6400a2eaa546d82ce5fe8222e455c5f85ce1ba7.
Validated new findings
- P2 verified: custom JavaScript
HttpClientimplementations that reject completed non-success responses cannot reach the new long-polling refresh-challenge branch; polling closes instead. - P2 question: older frozen clients send the refresh token in
?id=, while the updated server requires the header. The incompatibility is proven, but the frozen evidence does not establish whether mixed-version compatibility is required.
Existing-feedback coverage
Frozen inline comments 4529602533, 4529602607, and 4529602684 already cover, respectively, the removed slow-policy test registration, loss of bodyless-404 negotiate guidance, and refresh requests not participating in long-polling shutdown cancellation. They were not republished; deduplication is not an endorsement or grade of those reviews. Feedback after bundle preparation was not observable.
Guide completion
docs/CrossCuttingGuidance.md: complete; public/protocol compatibility, async/cancellation, lifetime, diagnostics, options, correctness, and test-source checks assessed.docs/BlazorComponentsGuidance.md: complete; interactive authentication flow, circuit continuity, DI registration, browser-test source, and hosting boundaries assessed.- Both workers used requested model
gpt-5.6-sol; reasoning effort was not supplied (runtime default).
Unresolved and uncovered
Formal public-API approval remains human-owned and is not established by this bundle. SignalR protocol/client/server behavior had no routed SignalR-specialist guide and was assessed through the cross-cutting guide only. Runtime/browser execution and security assessment were excluded by the trusted guidance.
Provenance and test boundary
Evidence was limited to the complete version-2 frozen bundle: head a6400a2eaa546d82ce5fe8222e455c5f85ce1ba7, merge base f3c1ff71b9b4a679d2d03ec7f6af5ad408e8a1a6, base tip and guidance commit d45f33d4f7a2261ed922785a656ef20407fe3847. No target code, tests, CI, or browser workflows were executed. Tracked Git bytes only; symlink, submodule, and LFS targets cannot be established from pointers.
Generated by ASP.NET Core Pull Request Review for #70452 · copilot · gpt56 · 268.4 AIC · ⌖ 12.6 AIC · ⊞ 18.8K
Comment /review to run again
| this._logger.log(LogLevel.Trace, `(LongPolling transport) polling: ${pollUrl}.`); | ||
| const response = await this._httpClient.get(pollUrl, pollOptions); | ||
|
|
||
| if (!authenticationRefreshAttempted |
There was a problem hiding this comment.
P2 — Preserve refresh challenges for custom HttpClient implementations
IHttpConnectionOptions.httpClient is public, and the frozen client contract allowed a completed non-success response to reject; both built-in clients did so. This branch is reached only after get() resolves, so an existing compliant custom client that rejects the server's 409 skips challenge handling, stops polling in the catch path, and closes without refreshing.
Minimal repro: provide a custom HttpClient that rejects HTTP 409 with HttpError, select Long Polling, and let the server return {"error":"authentication_refresh_required"}. The refresh callback is never invoked and the poll is not retried.
Please preserve the prior custom-client contract—for example, retain structured response content on HttpError and normalize a rejected 409 into the same challenge path before deciding to close the transport.
| var connectionToken = GetConnectionToken(context); | ||
| // Unlike transport requests, /refresh requires the private connection token in a non-safelisted | ||
| // header so a cross-origin browser request must successfully complete a CORS preflight. | ||
| var connectionToken = context.Request.Headers[ConnectionTokenHeaderName]; |
There was a problem hiding this comment.
P2 question — Is this behavior change on query-only authentication-refresh requests intended?
The frozen base-tip JavaScript and .NET clients post /refresh?id=<connectionToken>, while this line now reads only X-SignalR-Connection-Token. A server-only upgrade therefore returns HTTP 400 missing_connection_token before lookup or user-state update. The mismatch is source-proven, but the frozen bundle contains no binding contract requiring mixed-version compatibility, and the new tests explicitly assert query-only rejection.
Minimal repro: connect a frozen base-tip client with negotiate v1 to the head server and invoke authentication refresh; the request contains the query token but no new header, so refresh fails.
If mixed-version deployments are expected, retain a transitional query-token path or negotiate the header capability before requiring it.
Co-authored-by: Copilot <[email protected]> Copilot-Session: fdac132c-0926-4fda-8c97-88ae5b59b9fd
|
ℹ️ This pull request wasn't processed automatically. This change requires specialized review. Please confirm whether documentation updates are needed and handle them through the appropriate process. |
Port the upstream fix for CVE-2026-109481 from dotnet/aspnetcore main (PR dotnet#70452, merge commit d8754d1) onto the OpenHarmony feature branch. - Server: /refresh now requires the private X-SignalR-Connection-Token header (not the query string) so cross-origin requests must pass a CORS preflight; long polling answers 409 authentication_refresh_required when a poll carries a different user and legacy refresh is not enabled. - Clients: the C# and TypeScript clients send the token header, retry the poll after a refresh, and surface non-success responses instead of throwing inside the HTTP stack. - Tests: C#/TS client tests, dispatcher tests, CORS metadata test, Blazor auth test assets, and the transport protocol spec. Release/11.0 adaptation: the PR's ConnectionBindingRefresh test file and the negotiated-user tests (RefreshBeforeFirstGetRejectsDifferentNegotiated- UserDespitePermissivePolicies, RefreshBeforeFirstGetRejectsNegotiatedWindows- Identity, FirstGetRejectsDifferentUserAfterPreConnectRefresh) are omitted because the ConnectionBindingRefresh/negotiatedUser feature is not present on this branch. The rest of the PR patch applied as-is. Verification is source/diff level: aspnetcore cannot be built on the OpenHarmony host. Do not use the release-branch temporary port (34c4948) that lacks the server header.
The three removed tests (RefreshFromDifferentUserIsRejectedWhenTokenIsStale, RefreshFromDifferentUserIsRejectedWhenRejectionRacesConcurrentUserUpdate and LongPollingDifferentUserIsRejectedWhenRefreshRejectionRacesConcurrentUserUpdate) exercise the main-only stale/negotiated-identity hardening from 7f76fd3 ("Bind SignalR connections to negotiated identity"), which is not present on release/11.0. The dotnet#70452 security fix itself (header-only /refresh token and the long-polling 409) is unchanged; track the identity-binding hardening separately.
… tests The identity-binding cherry-pick brought the pre-dotnet#70452 test bodies: the shared refresh helper still used the query-string token and the race test expected the pre-header status. Replace the file with the upstream PR head version, which contains both the identity-binding and dotnet#70452 test changes.
Backport 7f76fd3 ("Bind SignalR connections to negotiated identity") on top of the dotnet#70452 port, matching the validated release branch tree. This restores the stale-race rejection, the negotiate-identity binding, the ConnectionBindingRefresh coverage and the three stale-race tests that the earlier dotnet#70452-only port had to omit. Validated on the release branch by ohos-signalr-verify run 43389845356.


Description
Require SignalR authentication-refresh requests to carry a non-simple request header and update long-polling clients to refresh authentication only after an explicit server challenge. This prevents cross-site simple requests from driving authentication refresh.
This addresses CVE-2026-109481.
Validation
npm run build --workspace @microsoft/signalrnpx jest --config .\jest.config.js --runInBand signalr/tests/HttpConnection.AuthenticationRefresh.test.ts signalr/tests/LongPollingTransport.test.ts signalr/tests/Utils.SendMessage.test.ts— 25 tests passedManaged and browser tests were not completed locally because the current repository bootstrap selected an MSBuild version below the repository SDK minimum; normal PR CI is required before merge.