git.iko.soy/typeable/oauth2-proxy
on master help sign in
Enable UseEncodedPath() for frontend mux

This allows urls with encoded characters (e.g.: /%2F/) to pass to the upstream mux instead of triggering a HTTP 301 from the frontend. Otherwise a /%2F/test/ will result in a HTTP 301 -> /test/

commitae72beb24ef94eef4cf31113c5910c884a368965 authorFabian Stelzer <fs@gigacodes.de> dateMon 9 Aug 2021, 12:46 (5 years ago) parentccbb98a
2 files changed+12−1
oauthproxy.go+3−1 oauthproxy_test.go+9
oauthproxy.go+3−1
@@ -265,7 +265,9 @@ func (p *OAuthProxy) setupServer(opts *options.Options) error {
265265}
266266
267267func (p *OAuthProxy) buildServeMux(proxyPrefix string) {
268− r := mux.NewRouter()
268+ // Use the encoded path here so we can have the option to pass it on in the upstream mux.
269+ // Otherwise something like /%2F/ would be redirected to / here already.
270+ r := mux.NewRouter().UseEncodedPath()
269271 // Everything served by the router must go through the preAuthChain first.
270272 r.Use(p.preAuthChain.Then)
271273
oauthproxy_test.go+9
@@ -915,6 +915,15 @@ func TestUserInfoEndpointUnauthorizedOnNoCookieSetError(t *testing.T) {
915915 assert.Equal(t, http.StatusUnauthorized, test.rw.Code)
916916}
917917
918+func TestEncodedUrlsStayEncoded(t *testing.T) {
919+ encodeTest, err := NewSignInPageTest(false)
920+ if err != nil {
921+ t.Fatal(err)
922+ }
923+ code, _ := encodeTest.GetEndpoint("/%2F/test1/%2F/test2")
924+ assert.Equal(t, 403, code)
925+}
926+
918927func NewAuthOnlyEndpointTest(querystring string, modifiers ...OptionsModifier) (*ProcessCookieTest, error) {
919928 pcTest, err := NewProcessCookieTestWithOptionsModifiers(modifiers...)
920929 if err != nil {