dotnet / dotnet/aspnetcore

SignalR - Ability to run middleware before the hub dispatcher

Open
#59,015 5 comments 0 reactions 0 assignees View on GitHub
area-signalr
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

When using web sockets, hub method invocations will silently fail in production if the request is invalid for one of the following reasons:
- method does not exist
- type mismatch
- missing parameter
- ...

In DEBUG mode we have such log:
![Image](https://github.com/user-attachments/assets/e4046eeb-58ea-4d62-bebd-baa1ca5b8196)

This is a problem because we cannot
- rate limit the bad method invocations
- log such method invocation (a bad client could continuously make bad requests and they would be invisible)

The common solution to add middleware to the pipeline is via hub filters, but those run after the hub dispatcher, meaning they will never run in case of bad request.

### Describe the solution you'd like

The ability to run code before the hub dispatcher (or anywhere before the request failure, I do not know all the details of what happens before the hub filters), which would allow to implement extra behaviours (rate limiter, invocation logging, ...) even if the request is malformed.

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.