Skip to content

Reject authentication schemes on SignalR hub methods - #68786

Open
BrennanConroy wants to merge 1 commit into
mainfrom
brennanconroy-signalr-authorization-check
Open

Reject authentication schemes on SignalR hub methods#68786
BrennanConroy wants to merge 1 commit into
mainfrom
brennanconroy-signalr-authorization-check

Conversation

@BrennanConroy

@BrennanConroy BrennanConroy commented Aug 25, 2026

Copy link
Copy Markdown
Member

Reject authentication schemes on SignalR hub methods

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue. N/A for this follow-up.

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 AuthenticationSchemes on hub methods during hub discovery with a clear NotSupportedException. 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:

private static void EnsureNoAuthenticationSchemeSpecified(object[] metadata)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings August 25, 2026 19:40
@BrennanConroy BrennanConroy added the area-signalr Includes: SignalR clients and servers label Aug 25, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 DefaultHubDispatcher that throws when method-level IAuthorizeData.AuthenticationSchemes is 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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-signalr Includes: SignalR clients and servers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants