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

Use the httputil.NewSingleHostReverseProxy instead of yhat/wsutil for … #1348

Merged
merged 5 commits into from
Oct 3, 2021

Conversation

thetrime
Copy link
Contributor

@thetrime thetrime commented Sep 1, 2021

…websocket proxying. This correctly handles 404 responses with keep-alive by terminating the tunnel rather than keeping it alive

Description

httputil has handled websockets natively since go1.12. The upstream package yhat/wsutil hasn't been updated in years and fails to handle some edge cases

Motivation and Context

This proposal fixes #1347

How Has This Been Tested?

The change is relatively localised. The way I tested it was as follows:

  1. I created a simple web server which echoed everything it received, and after receiving two newlines, wrote back this string: HTTP/1.1 404 Not Found\nContent-Type: text/plain\nConnection: keep-alive\nContent-length: 7\n\nMissing
  2. I tested the unpatched version of oauth2-proxy by opening a telnet session to it and pasting in a canned request twice. This request had the following features:
    • Upgrade: websocket
    • Connection: upgrade
    • Cookie: < a cookie corresponding to a valid oauth2-proxy session >
  3. The first request arrived at my test server with an Authorization: header. The second request did not.
  4. I then tested the patched version of oauth2-proxy in the same way
  5. The first request arrived at my test server with an Authorization: header. The second request did as well.

Checklist:

  • My change requires a change to the documentation or CHANGELOG.
  • I have updated the documentation/CHANGELOG accordingly.
  • I have created a feature (non-master) branch for my PR.

This should probably be mentioned in the changelog, but it shouldn't break anything that doesn't rely on what should be considered broken behaviour

…websocket proxying. This correctly handles 404 responses with keep-alive by terminating the tunnel rather than keeping it alive
@thetrime thetrime requested a review from a team as a code owner September 1, 2021 08:20
Copy link
Member

@JoelSpeed JoelSpeed left a comment

Choose a reason for hiding this comment

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

Changes look reasonable to me, could you run a go mod tidy as I think it should probably remove the dependency from our dependency tree now.

Also please add a changelog. I'll try and find some time to take this for a test run before we merge if that's ok 🙂

@NickMeves
Copy link
Member

This is the one tricky area with websockets in particular that likely need a manual test:

// Hijack implements the `http.Hijacker` interface that actual ResponseWriters

If I recall, if this isn't working right, our access logs will drop authenticated user information (email & user fields in the logs). Eyeballing those in your manual tests might be a good final check.

@thetrime
Copy link
Contributor Author

thetrime commented Sep 6, 2021

Changes look reasonable to me, could you run a go mod tidy as I think it should probably remove the dependency from our dependency tree now.

Also please add a changelog. I'll try and find some time to take this for a test run before we merge if that's ok 🙂

No problem. As @NickMeves mentioned, this is quite hard to test in an automated way. It's certainly beyond the scope of my Go knowledge to set up and tear down the necessary HTTP servers. I have a test rig, but it's written in Prolog [don't ask].

The gist is that the server can respond with HTTP 404 to everything while logging all the headers it receives. If you try and do a websocket connection to the server twice, the first time you'll see the cookie translated into an authentication header, and the second time you won't.

@JoelSpeed
Copy link
Member

Just trying to work out how to improve testing around this area and came across https://ieftimov.com/post/testing-in-go-websockets/, @thetrime I don't know if this is something you'd want to look into as a learning exercise? I know you said your Go knowledge isn't massive. If you don't want to delve to deep, I can look into extending the tests here to make sure we are covering this change at some point, let me know what you want to do

@thetrime
Copy link
Contributor Author

Just trying to work out how to improve testing around this area and came across https://ieftimov.com/post/testing-in-go-websockets/, @thetrime I don't know if this is something you'd want to look into as a learning exercise? I know you said your Go knowledge isn't massive. If you don't want to delve to deep, I can look into extending the tests here to make sure we are covering this change at some point, let me know what you want to do

Unfortunately I don't have time to do this now; realistically it'd probably be months before I could find time to sit down and teach myself another language. If you have the resources to implement a test framework, or can find someone else to do it, that'd definitely be the fastest road to getting it resolved

Copy link
Member

@JoelSpeed JoelSpeed left a comment

Choose a reason for hiding this comment

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

Had a chance to test drive this now, seems to be working as before, thanks @thetrime

@JoelSpeed JoelSpeed merged commit 3957183 into oauth2-proxy:master Oct 3, 2021
w3st3ry pushed a commit to instadeepai/oauth2-proxy that referenced this pull request Oct 5, 2021
… … (oauth2-proxy#1348)

* Use the httputil.NewSingleHostReverseProxy instad of yhat/wsutil for websocket proxying. This correctly handles 404 responses with keep-alive by terminating the tunnel rather than keeping it alive

* Tidy up dependencies - yhat/wsutil is no longer required

* Update changelog to include reference to 1348

Co-authored-by: Matt Lilley <matt.lilley@securitease.com>
Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>
k-jell pushed a commit to liquidinvestigations/oauth2-proxy that referenced this pull request Apr 6, 2022
… … (oauth2-proxy#1348)

* Use the httputil.NewSingleHostReverseProxy instad of yhat/wsutil for websocket proxying. This correctly handles 404 responses with keep-alive by terminating the tunnel rather than keeping it alive

* Tidy up dependencies - yhat/wsutil is no longer required

* Update changelog to include reference to 1348

Co-authored-by: Matt Lilley <matt.lilley@securitease.com>
Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>
Jing-ze pushed a commit to Jing-ze/oauth2-proxy that referenced this pull request Nov 19, 2024
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.

After forwarding a websocket request which fails, subsequent reuse of the connection does not get auth headers
3 participants