Skip to content
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

Investigate 401 handling for WebSocket #39

Open
annevk opened this issue Jun 16, 2018 · 5 comments
Open

Investigate 401 handling for WebSocket #39

annevk opened this issue Jun 16, 2018 · 5 comments

Comments

@annevk
Copy link
Member

annevk commented Jun 16, 2018

This is a follow-up to whatwg/fetch#565 and whatwg/fetch#761 (comment) in particular.

It'd be good to write more tests that cover the various scenarios:

  1. Not authenticated, server replies with 401
  2. Authenticated via fetch() with Authorization before opening the web socket connection.
  3. 2, but server replies with a 401 anyway.
  4. More?

Not sure all of those are easy to do in web-platform-tests given that authentication entries likely don't cross ports...

And review the algorithms in the standard again to ensure no prompting can take place ever (and maybe check again if implementations have the necessary bugs if they don't implement that).

@annevk
Copy link
Member Author

annevk commented Jun 16, 2018

websockets/basic-auth.any.js is an initial test by @ricea.

@ricea
Copy link
Collaborator

ricea commented Jun 18, 2018

The difficulty with preflighting auth via XHR or fetch is that the pywebsocket API doesn't support basic auth for plain HTTP except by restarting it with different command-line arguments. I had an idea yesterday that we can test this more easily by using the regular (non-WebSocket) wptserve, but returning a 404 after auth succeeds. We won't be able to tell whether it succeeded using the WebSocket API, but we can ask the server whether auth succeeded after the WebSocket onclose handler is called.

Another trick I've used in the past is to return a canned WebSocket response containing only a close frame from an HTTP-only server. That's probably harder to understand than the 404 trick, however.

I don't have time to dedicate to this at the moment, but I will try to fit it in.

A case I'm particularly interested in trying is a digest authentication like this:

  1. Cache credentials with XHR. HTTP GET / 401 response requesting digest auth / HTTP GET with Auth / 200 response sequence.
  2. WebSocket GET without auth (some browsers may send auth immediately in some cases? the test should be flexible about this)
  3. Server responds with 401 requesting digest auth
  4. WebSocket GET with digest auth
  5. Server responds with 401, indicating stale nonce, provides new nonce
  6. WebSocket GET with digest auth, using new nonce
  7. Success!

The idea is to get close to the multi-stage auth used by NTLM or Negotiate, without hitting the weird platform-specific behaviour that NTLM and Negotiate imply.

@annevk
Copy link
Member Author

annevk commented Jun 18, 2018

Thanks, I don't think there's any particular rush, but that sounds like a good strategy (I was also wondering how this would work with web-platform-tests and did not think of that trick).

We should also test @dveditz's scenario with differing realms.

@sleevi
Copy link

sleevi commented Jun 18, 2018 via email

@ricea
Copy link
Collaborator

ricea commented Jun 18, 2018

@sleevi The part I'm interesting in exercising is handling more than one 401 response in the process of establishing a single WebSocket connection. I should have just said that explicitly, sorry.

Obviously it would be better to test real multi-stage auth, but I know of no realistically achievable way to do that in the web platform tests.

@annevk annevk transferred this issue from whatwg/fetch Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants