Repository navigation
[SignalR] Bind connection tokens to their endpoint mapping - #69279
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No unresolved review comments remain, and coverage passes.
Pull request overview
Binds SignalR connection tokens to their originating MapConnections registration, preventing cross-endpoint reuse.
Changes:
- Adds opaque per-mapping endpoint identity metadata.
- Enforces identity matching across token-consuming paths.
- Adds integration coverage for HTTP, WebSocket, and refresh scenarios.
File summaries
| File | Summary |
|---|---|
src/SignalR/common/Http.Connections/test/Microsoft.AspNetCore.Http.Connections.Tests.csproj |
Adds the TestHost dependency. |
src/SignalR/common/Http.Connections/test/MapConnectionHandlerTests.cs |
Tests endpoint isolation and same-mapping behavior. |
src/SignalR/common/Http.Connections/src/Internal/HttpConnectionManager.cs |
Stores and validates mapping identity. |
src/SignalR/common/Http.Connections/src/Internal/HttpConnectionEndpoint.cs |
Defines the internal mapping marker. |
src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.cs |
Propagates and enforces endpoint identity. |
src/SignalR/common/Http.Connections/src/Internal/HttpConnectionContext.cs |
Stores the originating mapping identity. |
src/SignalR/common/Http.Connections/src/ConnectionEndpointRouteBuilderExtensions.cs |
Applies shared identity metadata to mapped endpoints. |
Review details
- Files reviewed: 7/7 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
|
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). 2 pipeline(s) were filtered out due to trigger conditions. |
|
/backport to release/11.0 |
|
Started backporting to |
|
✅ No documentation PR was created. Confidence that documentation is needed: 15% No docs needed: internal fix binding connection tokens to their MapConnections mapping, with no public API or configuration changes. Documentation surfaces considered
|
…69835) Co-authored-by: Javier Calvarro Nelson <[email protected]>
Fixes #69090
Summary
MapConnectionsregistration an opaque internal mapping identity shared by its negotiate, authentication-refresh, and transport endpointsHttpConnectionManagerbefore token-consuming paths divergeDesign
MapConnectionscreates one privateHttpConnectionEndpointMetadatamarker and adds the same instance to the metadata for its negotiate, optional authentication-refresh, and transport endpoints. The instance must remain unique to thatMapConnectionsinvocation and must not be cached or reused globally. The dispatcher reads the marker fromHttpContext.GetEndpoint()rather than receiving it through captured handler parameters. The negotiated connection retains that object reference, and manager lookup succeeds only when the consuming endpoint supplies the same identity.The marker is intentionally data-free: its object identity represents the endpoint group. It is not derived from route text, and the separate routing
Endpointinstances cannot be compared directly because negotiate, refresh, and transport are distinct endpoints. No public API is added.Enforcement covers the shared execute entrypoint and the token-consuming send, poll, delete, Server-Sent Events, WebSockets/reconnect, and authentication-refresh paths. Direct WebSocket connections without negotiation are created with the current mapping identity as well.
Tests
The issue was faithfully reproduced before the fix with two mapped endpoints:
CloseOnAuthenticationExpiration = falseCloseOnAuthenticationExpiration = trueThe final coverage follows the existing dispatcher test infrastructure without TestHost:
GetOrCreateConnectionAsyncrejects a negotiated token on the wrong mapping with HTTP 404 while the originating mapping retains ownershipPOST /refreshrejects a negotiated token on the wrong mapping with HTTP 404 andconnection_not_found, while refresh remains successful on the originating mappingMapConnectionsregistration share the same metadata instance, while separate registrations receive different instancesRemoving only the centralized reference-identity comparison makes all three dispatcher cases fail with
expected 404, actual 200; all pass with enforcement restored.Microsoft.AspNetCore.Http.Connections.Tests: 288 passed, 0 failed, 0 skipped.Compatibility and deployment considerations
MapConnectionsregistrations.HttpConnectionManager; deployments still require the same routing affinity/stickiness. This change adds no distributed identity or serialization contract.