-
-
Notifications
You must be signed in to change notification settings - Fork 985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong unauthorized WebSocket status code #1362
Comments
I'm not 100% sure but after checking the code I think this might be happening In Uvicorn. What do you think @Kludex ? |
Is it related to this? encode/uvicorn#1181 |
I guess they are related, they point to the same code but not exactly the same issue. |
I think this should probably be discussed in Uvicorn, but out of curiosity I've checked def serverReject(self):
"""
Called when we get a message saying to reject the connection.
"""
self.handshake_deferred.errback(
ConnectionDeny(code=403, reason="Access denied")
)
del self.handshake_deferred The HTTP status of WebSocket rejection is hard-coded, I don't have much info about Uvicorn but maybe @Kludex or @euri10 can check the possibility to see if we can override that from Starlette. |
AuthenticationMiddleware sends This is the only possible behavior with regular ASGI server, but there is an ASGI extension that allows sending custom HTTP responses. I have implemented this for ExceptionMiddleware, should be straightforward to do the same for AuthenticationMiddleware |
Update: I implemented this in my PR: #1478 |
I see. Thanks for clarifying @paulo-raca. 👍 We'd still need to implement the extension on uvicorn's side. |
We are going to document this behavior first on #1636. At some point, I'll take a look at the implementation of the WebSocket Denial Response by @paulo-raca. There are a couple of things in the list before that, but we are going to get there - I'm not confirming we are going to have the extension, it needs to be discussed, and we need to see if it's worth it. Note: An implementation on the uvicorn needs to take place as well. |
Checklist
master
.Describe the bug
I have a protected websocket endpoint, with the decorator
@requires('authenticated', status_code=401)
.If the authentication check fails, the response code from the websocket is
403 Forbidden
, but it should be401 Unauthorized
.To reproduce
Here an example to reproduce the use case.
Expected behavior
The websocket endpoint should return 401, according to the status_code specified in the
@requires
decorator.Actual behavior
The websocket endpoint should return 403, even if I specify the desired status_code in the
@requires
decorator.Environment
The text was updated successfully, but these errors were encountered: