git.iko.soy/typeable/oauth2-proxy
on master help sign in
fix: websocket path rewrite (#2300)
commit64e736f6682ebe883b6087de0e0f888042a3dfb1 authorReto Kupferschmid <kupferschmid@puzzle.ch> dateMon 4 Nov 2024, 23:12 (2 years ago) parent96f0288
4 files changed+13−4
CHANGELOG.md+1−1 pkg/upstream/proxy_test.go+3−3 pkg/upstream/rewrite.go+1 pkg/upstream/rewrite_test.go+8
CHANGELOG.md+1−1
@@ -11,6 +11,7 @@
1111- [#2800](https://github.com/oauth2-proxy/oauth2-proxy/pull/2800) Add some opencontainer labels to docker image (@halkeye)
1212- [#2755](https://github.com/oauth2-proxy/oauth2-proxy/pull/2755) feat: add X-Envoy-External-Address as supported header (@bjencks)
1313- [#1985](https://github.com/oauth2-proxy/oauth2-proxy/pull/1985) Add support for systemd socket (@isodude)
14+- [#2300](https://github.com/oauth2-proxy/oauth2-proxy/pull/2300) Add fix for websocket path rewrite (@rekup)
1415
1516# V7.7.1
1617
@@ -59,7 +60,6 @@
5960- [#2790](https://github.com/oauth2-proxy/oauth2-proxy/pull/2790) chore(deps): update all golang dependencies (@tuunit)
6061- [#2607](https://github.com/oauth2-proxy/oauth2-proxy/pull/2607) fix(csrf): fix possible infinite loop (@Primexz)
6162
62−
6363# V7.6.0
6464
6565## Release Highlights
pkg/upstream/proxy_test.go+3−3
@@ -253,7 +253,7 @@ var _ = Describe("Proxy Suite", func() {
253253 URL: "http://example.localhost/different/backend/path/1234",
254254 Header: map[string][]string{
255255 "Gap-Auth": {""},
256− "Gap-Signature": {"sha256 jeAeM7wHSj2ab/l9YPvtTJ9l/8q1tpY2V/iwXF48bgw="},
256+ "Gap-Signature": {"sha256 Pzy0fSFhzbhY0R9rj8vl5LCiIQaKVB0s6h9BADgIT4I="},
257257 },
258258 Body: []byte{},
259259 Host: "example.localhost",
@@ -274,7 +274,7 @@ var _ = Describe("Proxy Suite", func() {
274274 URL: "http://example.localhost/different/backend/path/1234/abc",
275275 Header: map[string][]string{
276276 "Gap-Auth": {""},
277− "Gap-Signature": {"sha256 rAkAc9gp7EndoOppJuvbuPnYuBcqrTkBnQx6iPS8xTA="},
277+ "Gap-Signature": {"sha256 uqIAxSgz+onqHDMMl/EAZWbwSw56PzM90iCocNUEqmw="},
278278 },
279279 Body: []byte{},
280280 Host: "example.localhost",
@@ -324,7 +324,7 @@ var _ = Describe("Proxy Suite", func() {
324324 URL: "http://example.localhost/double-match/rewrite/foo",
325325 Header: map[string][]string{
326326 "Gap-Auth": {""},
327− "Gap-Signature": {"sha256 eYyUNdsrTmnvFpavpP8AdHGUGzqJ39QEjqn0/3fQPHA="},
327+ "Gap-Signature": {"sha256 Ii7wKYBkRkJH556gRUsVUwGPgF7IG7V7X4vhkiyzfQ0="},
328328 },
329329 Body: []byte{},
330330 Host: "example.localhost",
pkg/upstream/rewrite.go+1
@@ -50,6 +50,7 @@ func rewritePath(rewriteRegExp *regexp.Regexp, rewriteTarget string, writer page
5050 }
5151
5252 req.RequestURI = reqURL.String()
53+ req.URL.Path = reqURL.Path // set path for websocket connections
5354 next.ServeHTTP(rw, req)
5455 })
5556}
pkg/upstream/rewrite_test.go+8
@@ -16,6 +16,7 @@ var _ = Describe("Rewrite", func() {
1616 rewriteTarget string
1717 requestTarget string
1818 expectedRequestURI string
19+ expectedURLPath string
1920 }
2021
2122 DescribeTable("should rewrite the request path",
@@ -24,36 +25,43 @@ var _ = Describe("Rewrite", func() {
2425 rw := httptest.NewRecorder()
2526
2627 var gotRequestURI string
28+ var gotRequestURLPath string
2729 handler := newRewritePath(in.rewriteRegex, in.rewriteTarget, &pagewriter.WriterFuncs{})(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2830 gotRequestURI = r.RequestURI
31+ gotRequestURLPath = r.URL.Path
2932 }))
3033 handler.ServeHTTP(rw, req)
3134
3235 Expect(gotRequestURI).To(Equal(in.expectedRequestURI))
36+ Expect(gotRequestURLPath).To(Equal(in.expectedURLPath))
3337 },
3438 Entry("when the path matches the regexp", rewritePathTableInput{
3539 rewriteRegex: regexp.MustCompile("^/http/(.*)"),
3640 rewriteTarget: "/$1",
3741 requestTarget: "http://example.com/http/foo/bar",
3842 expectedRequestURI: "http://example.com/foo/bar",
43+ expectedURLPath: "/foo/bar",
3944 }),
4045 Entry("when the path does not match the regexp", rewritePathTableInput{
4146 rewriteRegex: regexp.MustCompile("^/http/(.*)"),
4247 rewriteTarget: "/$1",
4348 requestTarget: "https://example.com/https/foo/bar",
4449 expectedRequestURI: "https://example.com/https/foo/bar",
50+ expectedURLPath: "/https/foo/bar",
4551 }),
4652 Entry("when the regexp is not anchored", rewritePathTableInput{
4753 rewriteRegex: regexp.MustCompile("/http/(.*)"),
4854 rewriteTarget: "/$1",
4955 requestTarget: "http://example.com/bar/http/foo/bar",
5056 expectedRequestURI: "http://example.com/bar/foo/bar",
57+ expectedURLPath: "/bar/foo/bar",
5158 }),
5259 Entry("when the regexp is rewriting to a query", rewritePathTableInput{
5360 rewriteRegex: regexp.MustCompile(`/articles/([a-z0-9\-]*)`),
5461 rewriteTarget: "/article?id=$1",
5562 requestTarget: "http://example.com/articles/blog-2021-01-01",
5663 expectedRequestURI: "http://example.com/article?id=blog-2021-01-01",
64+ expectedURLPath: "/article",
5765 }),
5866 )
5967})