Skip to content

Add docs for applying CORS to SignalR hubs without global middleware#36936

Merged
wadepickett merged 8 commits intomainfrom
copilot/add-cors-support-signalr
Apr 1, 2026
Merged

Add docs for applying CORS to SignalR hubs without global middleware#36936
wadepickett merged 8 commits intomainfrom
copilot/add-cors-support-signalr

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 31, 2026

Fixes #12918 . Addressing really old backlog issues, a few a sprint per org goals. This one is terribly old but still a gap in the docs today.

Users need to apply CORS policies specifically to SignalR hub endpoints without enabling CORS globally via UseCors middleware. This is common when different parts of an app require different CORS configurations.

Adds a new "Apply a CORS policy to SignalR hub endpoints" subsection documenting two approaches:

// Option 1: RequireCors on endpoint mapping
app.MapHub<ChatHub>("/chatHub")
    .RequireCors("SignalRPolicy");

// Option 2: [EnableCors] attribute on Hub class
[EnableCors("SignalRPolicy")]
public class ChatHub : Hub { }
  • security.md — aspnetcore 8.0+ inline moniker only

Per reviewer feedback from @BrennanConroy, changes are scoped to supported versions only (8.0+). The unsupported-version includes (security7.md, security6.md, security2.1-5.md) are left unchanged.

Cross-references the existing Enable CORS with endpoint routing section.


Internal previews

📄 File 🔗 Preview link
aspnetcore/signalr/security.md Security considerations in ASP.NET Core SignalR

Internal previews

📄 File 🔗 Preview link
aspnetcore/signalr/security.md aspnetcore/signalr/security

…cy globally

Add a new subsection "Apply a CORS policy to SignalR hub endpoints" under the
CORS section in SignalR security docs. Documents two approaches:
1. Using RequireCors on the MapHub endpoint mapping
2. Using the [EnableCors] attribute on the Hub class

Applied across all relevant moniker versions (8.0+, 7.0, 6.0, 3.0-5.x).

Agent-Logs-Url: https://github.com/dotnet/AspNetCore.Docs/sessions/c6bf092e-343b-49ad-bfa1-e83078d9e265

Co-authored-by: wadepickett <10985336+wadepickett@users.noreply.github.com>
Copilot AI changed the title [WIP] Add content about enabling CORS for SignalR Add docs for applying CORS to SignalR hubs without global middleware Mar 31, 2026
Copilot AI requested a review from wadepickett March 31, 2026 23:46
@wadepickett
Copy link
Copy Markdown
Contributor

@copilot , The "SignalRPolicy" policy name used in code samples isn't defined anywhere in the preceding examples for any version. A brief note or example showing the named policy registration (like BrennanConroy's AddPolicy snippet) would improve clarity. See discussion comment from BrennanConroy on the original issue this PR is for here: #12918

…tion

Show the AddCors/AddPolicy snippet that defines "SignalRPolicy" before
it's referenced in the RequireCors and [EnableCors] examples.

Agent-Logs-Url: https://github.com/dotnet/AspNetCore.Docs/sessions/eeaca9de-513b-4a43-a838-4e3f6ca91450

Co-authored-by: wadepickett <10985336+wadepickett@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 1, 2026

@copilot , The "SignalRPolicy" policy name used in code samples isn't defined anywhere in the preceding examples for any version. A brief note or example showing the named policy registration (like Br...

Added the AddCors/AddPolicy registration snippet that defines the "SignalRPolicy" name before it's used in the RequireCors and [EnableCors] examples. The 8.0+, 7.0, and 6.0 versions use builder.Services.AddCors(...) (minimal hosting), while the 3.0–5.x version uses the Startup.ConfigureServices pattern. See commit 7a6d503.

Co-authored-by: Wade Pickett <wpickett@microsoft.com>
Co-authored-by: Wade Pickett <wpickett@microsoft.com>
@wadepickett wadepickett requested a review from Copilot April 1, 2026 01:09
@wadepickett wadepickett marked this pull request as ready for review April 1, 2026 01:09
@wadepickett wadepickett requested a review from tdykstra April 1, 2026 01:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds documentation to the SignalR security guidance showing how to apply a named CORS policy specifically to SignalR hub endpoints (instead of applying a single CORS policy globally), across ASP.NET Core versioned content.

Changes:

  • Add a new “Apply a CORS policy to SignalR hub endpoints” subsection with RequireCors and [EnableCors] approaches across 6.0/7.0/8.0+ and 3.0–5.x content.
  • Update aspnetcore/signalr/security.md front matter (adds ai-usage, updates ms.date) and include the new subsection for 8.0+.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.

File Description
aspnetcore/signalr/security.md Adds the new per-hub CORS subsection for 8.0+ and updates article metadata.
aspnetcore/signalr/security/includes/security7.md Adds the new per-hub CORS subsection for the 7.0 view.
aspnetcore/signalr/security/includes/security6.md Adds the new per-hub CORS subsection for the 6.0 view.
aspnetcore/signalr/security/includes/security2.1-5.md Adds the new per-hub CORS subsection for 3.0–5.x content (endpoint routing style).

Copy link
Copy Markdown
Contributor

@wadepickett wadepickett left a comment

Choose a reason for hiding this comment

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

Approved.

@wadepickett
Copy link
Copy Markdown
Contributor

@copilot, revert all changes to these files:

aspnetcore/signalr/security/includes/security2.1-5.md
aspnetcore/signalr/security/includes/security6.md
aspnetcore/signalr/security/includes/security7.md

Per BrennanConroy's feedback, these are unsupported versions and
don't need the CORS documentation update. The new CORS subsection
is retained only in security.md (aspnetcore 8.0+).

Agent-Logs-Url: https://github.com/dotnet/AspNetCore.Docs/sessions/c741589c-d9d2-40d2-ad8e-14eed4304350

Co-authored-by: wadepickett <10985336+wadepickett@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 1, 2026

@copilot, revert all changes to these files:

aspnetcore/signalr/security/includes/security2.1-5.md
...

Reverted all changes to those three files in 71e20c4. The CORS subsection is now only in security.md (aspnetcore 8.0+).

@wadepickett
Copy link
Copy Markdown
Contributor

Removed the update from the non-supported versions of the article.

@wadepickett wadepickett merged commit bdd837c into main Apr 1, 2026
4 checks passed
@wadepickett wadepickett deleted the copilot/add-cors-support-signalr branch April 1, 2026 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add content about enabling CORS for SignalR without applying the policy globally.

4 participants