Reject authentication schemes on SignalR hub methods - #68786
Open
BrennanConroy wants to merge 1 commit into
Open
Reject authentication schemes on SignalR hub methods#68786BrennanConroy wants to merge 1 commit into
BrennanConroy wants to merge 1 commit into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR prevents a confusing/ineffective authorization configuration in SignalR by rejecting non-empty AuthenticationSchemes specified on hub methods, since method-level authorization runs against an already-established connection ClaimsPrincipal and cannot re-authenticate. The rejection happens during hub method discovery with a clear NotSupportedException, and new tests cover the rejected method-level case while ensuring class-level schemes don’t trigger the new guard.
Changes:
- Add a hub discovery-time guard in
DefaultHubDispatcherthat throws when method-levelIAuthorizeData.AuthenticationSchemesis specified. - Add test hub types to represent class-level vs method-level scheme usage.
- Add unit tests verifying class-level schemes are allowed and method-level schemes are rejected with a specific message.
Show a summary per file
| File | Description |
|---|---|
| src/SignalR/server/SignalR/test/Microsoft.AspNetCore.SignalR.Tests/HubConnectionHandlerTestUtils/Hubs.cs | Adds hub fixtures for class-level and method-level AuthenticationSchemes scenarios. |
| src/SignalR/server/SignalR/test/Microsoft.AspNetCore.SignalR.Tests/HubConnectionHandlerTests.cs | Adds tests asserting method-level schemes throw and class-level schemes don’t. |
| src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs | Enforces “no AuthenticationSchemes on hub methods” during method discovery. |
Review details
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Lite
| // To avoid any confusion, ensure the developer isn't trying to specify a scheme. | ||
| for (var i = 0; i < authorizationMetadata.Count; i++) | ||
| { | ||
| if (authorizationMetadata[i] is IAuthorizeData entry && !string.IsNullOrEmpty(entry.AuthenticationSchemes)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reject authentication schemes on SignalR hub methods
Reject unsupported schemes on SignalR hub methods
Description
SignalR hub method authorization runs against the principal already established for the stateful connection, so a method-level authentication scheme cannot select or re-authenticate a principal and was silently ignored.
This change rejects nonempty
AuthenticationSchemeson hub methods during hub discovery with a clearNotSupportedException. Authentication schemes remain supported on hub classes, where endpoint authorization can apply them. Tests cover both the supported class-level case and rejected method-level case.Stole this change from Components:
aspnetcore/src/Components/Authorization/src/AuthorizeViewCore.cs
Line 126 in d013315