mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2025-03-21 21:47:11 +02:00
Merge pull request #1115 from oauth2-proxy/remove-force-query
Fix upstream proxy appending `?` to requests
This commit is contained in:
commit
b82182763e
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
## Changes since v7.0.1
|
## Changes since v7.0.1
|
||||||
|
|
||||||
|
- [#1115](https://github.com/oauth2-proxy/oauth2-proxy/pull/1115) Fix upstream proxy appending ? to requests (@JoelSpeed)
|
||||||
- [#1117](https://github.com/oauth2-proxy/oauth2-proxy/pull/1117) Deprecate GCP HealthCheck option (@JoelSpeed)
|
- [#1117](https://github.com/oauth2-proxy/oauth2-proxy/pull/1117) Deprecate GCP HealthCheck option (@JoelSpeed)
|
||||||
- [#1104](https://github.com/oauth2-proxy/oauth2-proxy/pull/1104) Allow custom robots text pages (@JoelSpeed)
|
- [#1104](https://github.com/oauth2-proxy/oauth2-proxy/pull/1104) Allow custom robots text pages (@JoelSpeed)
|
||||||
- [#1045](https://github.com/oauth2-proxy/oauth2-proxy/pull/1045) Ensure redirect URI always has a scheme (@JoelSpeed)
|
- [#1045](https://github.com/oauth2-proxy/oauth2-proxy/pull/1045) Ensure redirect URI always has a scheme (@JoelSpeed)
|
||||||
|
@ -116,11 +116,11 @@ func newReverseProxy(target *url.URL, upstream options.Upstream, errorHandler Pr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the request director based on the PassHostHeader option
|
// Ensure we always pass the original request path
|
||||||
|
setProxyDirector(proxy)
|
||||||
|
|
||||||
if upstream.PassHostHeader != nil && !*upstream.PassHostHeader {
|
if upstream.PassHostHeader != nil && !*upstream.PassHostHeader {
|
||||||
setProxyUpstreamHostHeader(proxy, target)
|
setProxyUpstreamHostHeader(proxy, target)
|
||||||
} else {
|
|
||||||
setProxyDirector(proxy)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the error handler so that upstream connection failures render the
|
// Set the error handler so that upstream connection failures render the
|
||||||
@ -137,10 +137,7 @@ func setProxyUpstreamHostHeader(proxy *httputil.ReverseProxy, target *url.URL) {
|
|||||||
director := proxy.Director
|
director := proxy.Director
|
||||||
proxy.Director = func(req *http.Request) {
|
proxy.Director = func(req *http.Request) {
|
||||||
director(req)
|
director(req)
|
||||||
// use RequestURI so that we aren't unescaping encoded slashes in the request path
|
|
||||||
req.Host = target.Host
|
req.Host = target.Host
|
||||||
req.URL.Opaque = req.RequestURI
|
|
||||||
req.URL.RawQuery = ""
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,6 +150,7 @@ func setProxyDirector(proxy *httputil.ReverseProxy) {
|
|||||||
// use RequestURI so that we aren't unescaping encoded slashes in the request path
|
// use RequestURI so that we aren't unescaping encoded slashes in the request path
|
||||||
req.URL.Opaque = req.RequestURI
|
req.URL.Opaque = req.RequestURI
|
||||||
req.URL.RawQuery = ""
|
req.URL.RawQuery = ""
|
||||||
|
req.URL.ForceQuery = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,16 +30,17 @@ var _ = Describe("HTTP Upstream Suite", func() {
|
|||||||
falsum := false
|
falsum := false
|
||||||
|
|
||||||
type httpUpstreamTableInput struct {
|
type httpUpstreamTableInput struct {
|
||||||
id string
|
id string
|
||||||
serverAddr *string
|
serverAddr *string
|
||||||
target string
|
target string
|
||||||
method string
|
method string
|
||||||
body []byte
|
body []byte
|
||||||
signatureData *options.SignatureData
|
passUpstreamHostHeader bool
|
||||||
existingHeaders map[string]string
|
signatureData *options.SignatureData
|
||||||
expectedResponse testHTTPResponse
|
existingHeaders map[string]string
|
||||||
expectedUpstream string
|
expectedResponse testHTTPResponse
|
||||||
errorHandler ProxyErrorHandler
|
expectedUpstream string
|
||||||
|
errorHandler ProxyErrorHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
DescribeTable("HTTP Upstream ServeHTTP",
|
DescribeTable("HTTP Upstream ServeHTTP",
|
||||||
@ -52,6 +53,9 @@ var _ = Describe("HTTP Upstream Suite", func() {
|
|||||||
for key, value := range in.existingHeaders {
|
for key, value := range in.existingHeaders {
|
||||||
req.Header.Add(key, value)
|
req.Header.Add(key, value)
|
||||||
}
|
}
|
||||||
|
if host := req.Header.Get("Host"); host != "" {
|
||||||
|
req.Host = host
|
||||||
|
}
|
||||||
|
|
||||||
req = middlewareapi.AddRequestScope(req, &middlewareapi.RequestScope{})
|
req = middlewareapi.AddRequestScope(req, &middlewareapi.RequestScope{})
|
||||||
rw := httptest.NewRecorder()
|
rw := httptest.NewRecorder()
|
||||||
@ -60,7 +64,7 @@ var _ = Describe("HTTP Upstream Suite", func() {
|
|||||||
|
|
||||||
upstream := options.Upstream{
|
upstream := options.Upstream{
|
||||||
ID: in.id,
|
ID: in.id,
|
||||||
PassHostHeader: &truth,
|
PassHostHeader: &in.passUpstreamHostHeader,
|
||||||
ProxyWebSockets: &falsum,
|
ProxyWebSockets: &falsum,
|
||||||
InsecureSkipTLSVerify: false,
|
InsecureSkipTLSVerify: false,
|
||||||
FlushInterval: &flush,
|
FlushInterval: &flush,
|
||||||
@ -140,6 +144,29 @@ var _ = Describe("HTTP Upstream Suite", func() {
|
|||||||
},
|
},
|
||||||
expectedUpstream: "encodedSlashes",
|
expectedUpstream: "encodedSlashes",
|
||||||
}),
|
}),
|
||||||
|
Entry("request a path with an empty query string", &httpUpstreamTableInput{
|
||||||
|
id: "default",
|
||||||
|
serverAddr: &serverAddr,
|
||||||
|
target: "http://example.localhost/foo?",
|
||||||
|
method: "GET",
|
||||||
|
body: []byte{},
|
||||||
|
errorHandler: nil,
|
||||||
|
expectedResponse: testHTTPResponse{
|
||||||
|
code: 200,
|
||||||
|
header: map[string][]string{
|
||||||
|
contentType: {applicationJSON},
|
||||||
|
},
|
||||||
|
request: testHTTPRequest{
|
||||||
|
Method: "GET",
|
||||||
|
URL: "http://example.localhost/foo?",
|
||||||
|
Header: map[string][]string{},
|
||||||
|
Body: []byte{},
|
||||||
|
Host: "example.localhost",
|
||||||
|
RequestURI: "http://example.localhost/foo?",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedUpstream: "default",
|
||||||
|
}),
|
||||||
Entry("when the request has a body", &httpUpstreamTableInput{
|
Entry("when the request has a body", &httpUpstreamTableInput{
|
||||||
id: "requestWithBody",
|
id: "requestWithBody",
|
||||||
serverAddr: &serverAddr,
|
serverAddr: &serverAddr,
|
||||||
@ -257,6 +284,33 @@ var _ = Describe("HTTP Upstream Suite", func() {
|
|||||||
},
|
},
|
||||||
expectedUpstream: "existingHeaders",
|
expectedUpstream: "existingHeaders",
|
||||||
}),
|
}),
|
||||||
|
Entry("when passing the existing host header", &httpUpstreamTableInput{
|
||||||
|
id: "passExistingHostHeader",
|
||||||
|
serverAddr: &serverAddr,
|
||||||
|
target: "/existingHostHeader",
|
||||||
|
method: "GET",
|
||||||
|
body: []byte{},
|
||||||
|
errorHandler: nil,
|
||||||
|
passUpstreamHostHeader: true,
|
||||||
|
existingHeaders: map[string]string{
|
||||||
|
"Host": "existing-host",
|
||||||
|
},
|
||||||
|
expectedResponse: testHTTPResponse{
|
||||||
|
code: 200,
|
||||||
|
header: map[string][]string{
|
||||||
|
contentType: {applicationJSON},
|
||||||
|
},
|
||||||
|
request: testHTTPRequest{
|
||||||
|
Method: "GET",
|
||||||
|
URL: "/existingHostHeader",
|
||||||
|
Header: map[string][]string{},
|
||||||
|
Body: []byte{},
|
||||||
|
Host: "existing-host",
|
||||||
|
RequestURI: "/existingHostHeader",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedUpstream: "passExistingHostHeader",
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
It("ServeHTTP, when not passing a host header", func() {
|
It("ServeHTTP, when not passing a host header", func() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user