git.iko.soy/typeable/oauth2-proxy
on master help sign in
Preserve query when building redirect (fix for #695) (#696)

* Add test for GetRedirect to check query and fragments. * Preserve query and fragment when building redirect. * Add changelog entry for redirect fix

commit88ef888752fb9b23d11ffd13d709a1bb3f495f4c authorAndy Voltz <anvoltz@microsoft.com> dateTue 21 Jul 2020, 11:38 (6 years ago) parentc5da3df
3 files changed+8−1
CHANGELOG.md+1 oauthproxy.go+2−1 oauthproxy_test.go+5
CHANGELOG.md+1
@@ -11,6 +11,7 @@
1111
1212## Changes since v6.0.0
1313
14+- [#696](https://github.com/oauth2-proxy/oauth2-proxy/pull/696) Preserve query when building redirect
1415- [#561](https://github.com/oauth2-proxy/oauth2-proxy/pull/561) Refactor provider URLs to package level vars (@JoelSpeed)
1516- [#682](https://github.com/oauth2-proxy/oauth2-proxy/pull/682) Refactor persistent session store session ticket management (@NickMeves)
1617- [#688](https://github.com/oauth2-proxy/oauth2-proxy/pull/688) Refactor session loading to make use of middleware pattern (@JoelSpeed)
oauthproxy.go+2−1
@@ -454,7 +454,8 @@ func (p *OAuthProxy) GetRedirect(req *http.Request) (redirect string, err error)
454454 redirect = req.Form.Get("rd")
455455 }
456456 if !p.IsValidRedirect(redirect) {
457− redirect = req.URL.Path
457+ // Use RequestURI to preserve ?query
458+ redirect = req.URL.RequestURI()
458459 if strings.HasPrefix(redirect, p.ProxyPrefix) {
459460 redirect = "/"
460461 }
oauthproxy_test.go+5
@@ -1678,6 +1678,11 @@ func TestGetRedirect(t *testing.T) {
16781678 url: "/foo/bar",
16791679 expectedRedirect: "/foo/bar",
16801680 },
1681+ {
1682+ name: "request with query preserves query",
1683+ url: "/foo?bar",
1684+ expectedRedirect: "/foo?bar",
1685+ },
16811686 {
16821687 name: "request under ProxyPrefix redirects to root",
16831688 url: proxy.ProxyPrefix + "/foo/bar",