git.iko.soy/typeable/oauth2-proxy
on master help sign in
Merge pull request #1115 from oauth2-proxy/remove-force-query
b821827Joel Speed
CHANGELOG.md+1
@@ -16,6 +16,7 @@
16
16
17## Changes since v7.0.1
17## Changes since v7.0.1
18
18
19+- [#1115](https://github.com/oauth2-proxy/oauth2-proxy/pull/1115) Fix upstream proxy appending ? to requests (@JoelSpeed)
19- [#1117](https://github.com/oauth2-proxy/oauth2-proxy/pull/1117) Deprecate GCP HealthCheck option (@JoelSpeed)
20- [#1117](https://github.com/oauth2-proxy/oauth2-proxy/pull/1117) Deprecate GCP HealthCheck option (@JoelSpeed)
20- [#1104](https://github.com/oauth2-proxy/oauth2-proxy/pull/1104) Allow custom robots text pages (@JoelSpeed)
21- [#1104](https://github.com/oauth2-proxy/oauth2-proxy/pull/1104) Allow custom robots text pages (@JoelSpeed)
21- [#1045](https://github.com/oauth2-proxy/oauth2-proxy/pull/1045) Ensure redirect URI always has a scheme (@JoelSpeed)
22- [#1045](https://github.com/oauth2-proxy/oauth2-proxy/pull/1045) Ensure redirect URI always has a scheme (@JoelSpeed)
pkg/upstream/http.go+4−6
@@ -116,11 +116,11 @@ func newReverseProxy(target *url.URL, upstream options.Upstream, errorHandler Pr
116 }
116 }
117 }
117 }
118
118
119− // Set the request director based on the PassHostHeader option
119+ // Ensure we always pass the original request path
120+ setProxyDirector(proxy)
121+
120 if upstream.PassHostHeader != nil && !*upstream.PassHostHeader {
122 if upstream.PassHostHeader != nil && !*upstream.PassHostHeader {
121 setProxyUpstreamHostHeader(proxy, target)
123 setProxyUpstreamHostHeader(proxy, target)
122− } else {
123− setProxyDirector(proxy)
124 }
124 }
125
125
126 // Set the error handler so that upstream connection failures render the
126 // Set the error handler so that upstream connection failures render the
@@ -137,10 +137,7 @@ func setProxyUpstreamHostHeader(proxy *httputil.ReverseProxy, target *url.URL) {
137 director := proxy.Director
137 director := proxy.Director
138 proxy.Director = func(req *http.Request) {
138 proxy.Director = func(req *http.Request) {
139 director(req)
139 director(req)
140− // use RequestURI so that we aren't unescaping encoded slashes in the request path
141 req.Host = target.Host
140 req.Host = target.Host
142− req.URL.Opaque = req.RequestURI
143− req.URL.RawQuery = ""
144 }
141 }
145}
142}
146
143
@@ -153,6 +150,7 @@ func setProxyDirector(proxy *httputil.ReverseProxy) {
153 // use RequestURI so that we aren't unescaping encoded slashes in the request path
150 // use RequestURI so that we aren't unescaping encoded slashes in the request path
154 req.URL.Opaque = req.RequestURI
151 req.URL.Opaque = req.RequestURI
155 req.URL.RawQuery = ""
152 req.URL.RawQuery = ""
153+ req.URL.ForceQuery = false
156 }
154 }
157}
155}
158
156
pkg/upstream/http_test.go+65−11
@@ -30,16 +30,17 @@ var _ = Describe("HTTP Upstream Suite", func() {
30 falsum := false
30 falsum := false
31
31
32 type httpUpstreamTableInput struct {
32 type httpUpstreamTableInput struct {
33− id string
33+ id string
34− serverAddr *string
34+ serverAddr *string
35− target string
35+ target string
36− method string
36+ method string
37− body []byte
37+ body []byte
38+ passUpstreamHostHeader bool
38− signatureData *options.SignatureData
39+ signatureData *options.SignatureData
39− existingHeaders map[string]string
40+ existingHeaders map[string]string
40− expectedResponse testHTTPResponse
41+ expectedResponse testHTTPResponse
41− expectedUpstream string
42+ expectedUpstream string
42− errorHandler ProxyErrorHandler
43+ errorHandler ProxyErrorHandler
43 }
44 }
44
45
45 DescribeTable("HTTP Upstream ServeHTTP",
46 DescribeTable("HTTP Upstream ServeHTTP",
@@ -52,6 +53,9 @@ var _ = Describe("HTTP Upstream Suite", func() {
52 for key, value := range in.existingHeaders {
53 for key, value := range in.existingHeaders {
53 req.Header.Add(key, value)
54 req.Header.Add(key, value)
54 }
55 }
56+ if host := req.Header.Get("Host"); host != "" {
57+ req.Host = host
58+ }
55
59
56 req = middlewareapi.AddRequestScope(req, &middlewareapi.RequestScope{})
60 req = middlewareapi.AddRequestScope(req, &middlewareapi.RequestScope{})
57 rw := httptest.NewRecorder()
61 rw := httptest.NewRecorder()
@@ -60,7 +64,7 @@ var _ = Describe("HTTP Upstream Suite", func() {
60
64
61 upstream := options.Upstream{
65 upstream := options.Upstream{
62 ID: in.id,
66 ID: in.id,
63− PassHostHeader: &truth,
67+ PassHostHeader: &in.passUpstreamHostHeader,
64 ProxyWebSockets: &falsum,
68 ProxyWebSockets: &falsum,
65 InsecureSkipTLSVerify: false,
69 InsecureSkipTLSVerify: false,
66 FlushInterval: &flush,
70 FlushInterval: &flush,
@@ -140,6 +144,29 @@ var _ = Describe("HTTP Upstream Suite", func() {
140 },
144 },
141 expectedUpstream: "encodedSlashes",
145 expectedUpstream: "encodedSlashes",
142 }),
146 }),
147+ Entry("request a path with an empty query string", &httpUpstreamTableInput{
148+ id: "default",
149+ serverAddr: &serverAddr,
150+ target: "http://example.localhost/foo?",
151+ method: "GET",
152+ body: []byte{},
153+ errorHandler: nil,
154+ expectedResponse: testHTTPResponse{
155+ code: 200,
156+ header: map[string][]string{
157+ contentType: {applicationJSON},
158+ },
159+ request: testHTTPRequest{
160+ Method: "GET",
161+ URL: "http://example.localhost/foo?",
162+ Header: map[string][]string{},
163+ Body: []byte{},
164+ Host: "example.localhost",
165+ RequestURI: "http://example.localhost/foo?",
166+ },
167+ },
168+ expectedUpstream: "default",
169+ }),
143 Entry("when the request has a body", &httpUpstreamTableInput{
170 Entry("when the request has a body", &httpUpstreamTableInput{
144 id: "requestWithBody",
171 id: "requestWithBody",
145 serverAddr: &serverAddr,
172 serverAddr: &serverAddr,
@@ -257,6 +284,33 @@ var _ = Describe("HTTP Upstream Suite", func() {
257 },
284 },
258 expectedUpstream: "existingHeaders",
285 expectedUpstream: "existingHeaders",
259 }),
286 }),
287+ Entry("when passing the existing host header", &httpUpstreamTableInput{
288+ id: "passExistingHostHeader",
289+ serverAddr: &serverAddr,
290+ target: "/existingHostHeader",
291+ method: "GET",
292+ body: []byte{},
293+ errorHandler: nil,
294+ passUpstreamHostHeader: true,
295+ existingHeaders: map[string]string{
296+ "Host": "existing-host",
297+ },
298+ expectedResponse: testHTTPResponse{
299+ code: 200,
300+ header: map[string][]string{
301+ contentType: {applicationJSON},
302+ },
303+ request: testHTTPRequest{
304+ Method: "GET",
305+ URL: "/existingHostHeader",
306+ Header: map[string][]string{},
307+ Body: []byte{},
308+ Host: "existing-host",
309+ RequestURI: "/existingHostHeader",
310+ },
311+ },
312+ expectedUpstream: "passExistingHostHeader",
313+ }),
260 )
314 )
261
315
262 It("ServeHTTP, when not passing a host header", func() {
316 It("ServeHTTP, when not passing a host header", func() {