@@ -54,7 +54,7 @@ func TestRobotsTxt(t *testing.T) {
5454 t.Fatal(err)
5555 }
5656 rw := httptest.NewRecorder()
57− req, _ := http.NewRequest("GET", "/robots.txt", nil)
57+ req, _ := http.NewRequest(http.MethodGet, "/robots.txt", nil)
5858 proxy.ServeHTTP(rw, req)
5959 assert.Equal(t, 200, rw.Code)
6060 assert.Equal(t, "User-agent: *\nDisallow: /\n", rw.Body.String())
@@ -241,7 +241,7 @@ func TestBasicAuthPassword(t *testing.T) {
241241
242242 // Save the required session
243243 rw := httptest.NewRecorder()
244− req, _ := http.NewRequest("GET", "/", nil)
244+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
245245 err = proxy.sessionStore.Save(rw, req, &sessions.SessionState{
246246 Email: emailAddress,
247247 })
@@ -250,7 +250,7 @@ func TestBasicAuthPassword(t *testing.T) {
250250 // Extract the cookie value to inject into the test request
251251 cookie := rw.Header().Values("Set-Cookie")[0]
252252
253− req, _ = http.NewRequest("GET", "/", nil)
253+ req, _ = http.NewRequest(http.MethodGet, "/", nil)
254254 req.Header.Set("Cookie", cookie)
255255 rw = httptest.NewRecorder()
256256 proxy.ServeHTTP(rw, req)
@@ -300,14 +300,14 @@ func TestPassGroupsHeadersWithGroups(t *testing.T) {
300300
301301 // Save the required session
302302 rw := httptest.NewRecorder()
303− req, _ := http.NewRequest("GET", "/", nil)
303+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
304304 err = proxy.sessionStore.Save(rw, req, session)
305305 assert.NoError(t, err)
306306
307307 // Extract the cookie value to inject into the test request
308308 cookie := rw.Header().Values("Set-Cookie")[0]
309309
310− req, _ = http.NewRequest("GET", "/", nil)
310+ req, _ = http.NewRequest(http.MethodGet, "/", nil)
311311 req.Header.Set("Cookie", cookie)
312312 rw = httptest.NewRecorder()
313313 proxy.ServeHTTP(rw, req)
@@ -457,7 +457,7 @@ func (patTest *PassAccessTokenTest) getEndpointWithCookie(cookie string, endpoin
457457 return 0, ""
458458 }
459459
460− req, err := http.NewRequest("GET", endpoint, strings.NewReader(""))
460+ req, err := http.NewRequest(http.MethodGet, endpoint, strings.NewReader(""))
461461 if err != nil {
462462 return 0, ""
463463 }
@@ -608,7 +608,7 @@ func NewSignInPageTest(skipProvider bool) (*SignInPageTest, error) {
608608
609609func (sipTest *SignInPageTest) GetEndpoint(endpoint string) (int, string) {
610610 rw := httptest.NewRecorder()
611− req, _ := http.NewRequest("GET", endpoint, strings.NewReader(""))
611+ req, _ := http.NewRequest(http.MethodGet, endpoint, strings.NewReader(""))
612612 sipTest.proxy.ServeHTTP(rw, req)
613613 return rw.Code, rw.Body.String()
614614}
@@ -713,6 +713,50 @@ func TestManualSignInCorrectCredentials(t *testing.T) {
713713 assert.Equal(t, http.StatusFound, statusCode)
714714}
715715
716+func TestSignInPageClearsExistingSessionCookie(t *testing.T) {
717+ opts := baseTestOptions()
718+ err := validation.Validate(opts)
719+ require.NoError(t, err)
720+
721+ proxy, err := NewOAuthProxy(opts, func(string) bool {
722+ return true
723+ })
724+ require.NoError(t, err)
725+
726+ // Create a real session cookie using the actual session store.
727+ saveRW := httptest.NewRecorder()
728+ saveReq := httptest.NewRequest(http.MethodGet, "/", nil)
729+ err = proxy.sessionStore.Save(saveRW, saveReq, &sessions.SessionState{
730+ Email: "john.doe@example.com",
731+ })
732+ require.NoError(t, err)
733+
734+ cookies := saveRW.Result().Cookies()
735+ require.NotEmpty(t, cookies)
736+
737+ // Send that cookie to the sign-in page.
738+ req := httptest.NewRequest(http.MethodGet, "/oauth2/sign_in", nil)
739+ for _, c := range cookies {
740+ req.AddCookie(c)
741+ }
742+
743+ rw := httptest.NewRecorder()
744+ proxy.ServeHTTP(rw, req)
745+
746+ assert.Equal(t, http.StatusOK, rw.Code)
747+
748+ cleared := false
749+ for _, c := range rw.Result().Cookies() {
750+ if c.Name == proxy.CookieOptions.Name {
751+ cleared = true
752+ assert.Equal(t, "", c.Value)
753+ assert.Less(t, c.MaxAge, 0)
754+ }
755+ }
756+
757+ assert.True(t, cleared, "expected sign-in page to clear existing session cookie")
758+}
759+
716760func TestSignInPageIncludesTargetRedirect(t *testing.T) {
717761 sipTest, err := NewSignInPageTest(false)
718762 if err != nil {
@@ -850,7 +894,7 @@ func NewProcessCookieTest(opts ProcessCookieTestOpts, modifiers ...OptionsModifi
850894 // access_token validation.
851895 pcTest.proxy.CookieOptions.Refresh = time.Duration(0)
852896 pcTest.rw = httptest.NewRecorder()
853− pcTest.req, _ = http.NewRequest("GET", "/", strings.NewReader(""))
897+ pcTest.req, _ = http.NewRequest(http.MethodGet, "/", strings.NewReader(""))
854898 pcTest.validateUser = true
855899 return &pcTest, nil
856900}
@@ -983,7 +1027,7 @@ func NewUserInfoEndpointTest() (*ProcessCookieTest, error) {
9831027 if err != nil {
9841028 return nil, err
9851029 }
986− pcTest.req, _ = http.NewRequest("GET",
1030+ pcTest.req, _ = http.NewRequest(http.MethodGet,
9871031 pcTest.opts.ProxyPrefix+"/userinfo", nil)
9881032 return pcTest, nil
9891033}
@@ -1091,7 +1135,7 @@ func NewAuthOnlyEndpointTest(querystring string, modifiers ...OptionsModifier) (
10911135 return nil, err
10921136 }
10931137 pcTest.req, _ = http.NewRequest(
1094− "GET",
1138+ http.MethodGet,
10951139 fmt.Sprintf("%s/auth%s", pcTest.opts.ProxyPrefix, querystring),
10961140 nil)
10971141 return pcTest, nil
@@ -1230,7 +1274,7 @@ func TestAuthOnlyEndpointSetXAuthRequestHeaders(t *testing.T) {
12301274 pcTest.validateUser = true
12311275
12321276 pcTest.rw = httptest.NewRecorder()
1233− pcTest.req, _ = http.NewRequest("GET",
1277+ pcTest.req, _ = http.NewRequest(http.MethodGet,
12341278 pcTest.opts.ProxyPrefix+authOnlyPath, nil)
12351279
12361280 created := time.Now()
@@ -1323,7 +1367,7 @@ func TestAuthOnlyEndpointSetBasicAuthTrueRequestHeaders(t *testing.T) {
13231367 pcTest.validateUser = true
13241368
13251369 pcTest.rw = httptest.NewRecorder()
1326− pcTest.req, _ = http.NewRequest("GET",
1370+ pcTest.req, _ = http.NewRequest(http.MethodGet,
13271371 pcTest.opts.ProxyPrefix+authOnlyPath, nil)
13281372
13291373 created := time.Now()
@@ -1403,7 +1447,7 @@ func TestAuthOnlyEndpointSetBasicAuthFalseRequestHeaders(t *testing.T) {
14031447 pcTest.validateUser = true
14041448
14051449 pcTest.rw = httptest.NewRecorder()
1406− pcTest.req, _ = http.NewRequest("GET",
1450+ pcTest.req, _ = http.NewRequest(http.MethodGet,
14071451 pcTest.opts.ProxyPrefix+authOnlyPath, nil)
14081452
14091453 created := time.Now()
@@ -1451,7 +1495,7 @@ func TestAuthSkippedForPreflightRequests(t *testing.T) {
14511495 }
14521496 proxy.provider = NewTestProvider(upstreamURL, "")
14531497 rw := httptest.NewRecorder()
1454− req, _ := http.NewRequest("OPTIONS", "/preflight-request", nil)
1498+ req, _ := http.NewRequest(http.MethodOptions, "/preflight-request", nil)
14551499 proxy.ServeHTTP(rw, req)
14561500
14571501 assert.Equal(t, 200, rw.Code)
@@ -1608,19 +1652,19 @@ func TestRequestSignature(t *testing.T) {
16081652 resp string
16091653 }{
16101654 "No request signature": {
1611− method: "GET",
1655+ method: http.MethodGet,
16121656 body: "",
16131657 key: "",
16141658 resp: "no signature received",
16151659 },
16161660 "Get request": {
1617− method: "GET",
1661+ method: http.MethodGet,
16181662 body: "",
16191663 key: "7d9e1aa87a5954e6f9fc59266b3af9d7c35fda2d",
16201664 resp: "signatures match",
16211665 },
16221666 "Post request": {
1623− method: "POST",
1667+ method: http.MethodPost,
16241668 body: `{ "hello": "world!" }`,
16251669 key: "d90df39e2d19282840252612dd7c81421a372f61",
16261670 resp: "signatures match",
@@ -2145,7 +2189,7 @@ func TestTrustedIPs(t *testing.T) {
21452189 reverseProxy: false,
21462190 realClientIPHeader: "X-Real-IP", // Default value
21472191 req: func() *http.Request {
2148− req, _ := http.NewRequest("GET", "/", nil)
2192+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
21492193 return req
21502194 }(),
21512195 expectTrusted: false,
@@ -2157,7 +2201,7 @@ func TestTrustedIPs(t *testing.T) {
21572201 reverseProxy: false,
21582202 realClientIPHeader: "X-Real-IP",
21592203 req: func() *http.Request {
2160− req, _ := http.NewRequest("GET", "/", nil)
2204+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
21612205 req.RemoteAddr = "@"
21622206 return req
21632207 }(),
@@ -2170,7 +2214,7 @@ func TestTrustedIPs(t *testing.T) {
21702214 reverseProxy: false,
21712215 realClientIPHeader: "X-Real-IP",
21722216 req: func() *http.Request {
2173− req, _ := http.NewRequest("GET", "/", nil)
2217+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
21742218 req.RemoteAddr = "@"
21752219 return req
21762220 }(),
@@ -2183,7 +2227,7 @@ func TestTrustedIPs(t *testing.T) {
21832227 reverseProxy: false,
21842228 realClientIPHeader: "X-Real-IP", // Default value
21852229 req: func() *http.Request {
2186− req, _ := http.NewRequest("GET", "/", nil)
2230+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
21872231 req.RemoteAddr = "127.0.0.1:43670"
21882232 return req
21892233 }(),
@@ -2196,7 +2240,7 @@ func TestTrustedIPs(t *testing.T) {
21962240 reverseProxy: true,
21972241 realClientIPHeader: "X-Real-IP", // Default value
21982242 req: func() *http.Request {
2199− req, _ := http.NewRequest("GET", "/", nil)
2243+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
22002244 req.RemoteAddr = "127.0.0.1:44324"
22012245 return req
22022246 }(),
@@ -2209,7 +2253,7 @@ func TestTrustedIPs(t *testing.T) {
22092253 reverseProxy: true,
22102254 realClientIPHeader: "X-Forwarded-For",
22112255 req: func() *http.Request {
2212− req, _ := http.NewRequest("GET", "/", nil)
2256+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
22132257 req.Header.Add("X-Forwarded-For", "127.0.0.1")
22142258 return req
22152259 }(),
@@ -2222,7 +2266,7 @@ func TestTrustedIPs(t *testing.T) {
22222266 reverseProxy: true,
22232267 realClientIPHeader: "X-Forwarded-For",
22242268 req: func() *http.Request {
2225− req, _ := http.NewRequest("GET", "/", nil)
2269+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
22262270 req.Header.Add("X-Forwarded-For", "::1")
22272271 return req
22282272 }(),
@@ -2235,7 +2279,7 @@ func TestTrustedIPs(t *testing.T) {
22352279 reverseProxy: true,
22362280 realClientIPHeader: "X-Forwarded-For",
22372281 req: func() *http.Request {
2238− req, _ := http.NewRequest("GET", "/", nil)
2282+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
22392283 req.Header.Add("X-Forwarded-For", "12.34.56.78")
22402284 return req
22412285 }(),
@@ -2248,7 +2292,7 @@ func TestTrustedIPs(t *testing.T) {
22482292 reverseProxy: true,
22492293 realClientIPHeader: "X-Forwarded-For",
22502294 req: func() *http.Request {
2251− req, _ := http.NewRequest("GET", "/", nil)
2295+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
22522296 req.Header.Add("X-Forwarded-For", "::2")
22532297 return req
22542298 }(),
@@ -2261,7 +2305,7 @@ func TestTrustedIPs(t *testing.T) {
22612305 reverseProxy: true,
22622306 realClientIPHeader: "X-Forwarded-For",
22632307 req: func() *http.Request {
2264− req, _ := http.NewRequest("GET", "/", nil)
2308+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
22652309 req.Header.Add("X-Real-IP", "::1")
22662310 return req
22672311 }(),
@@ -2274,7 +2318,7 @@ func TestTrustedIPs(t *testing.T) {
22742318 reverseProxy: true,
22752319 realClientIPHeader: "X-Forwarded-For",
22762320 req: func() *http.Request {
2277− req, _ := http.NewRequest("GET", "/", nil)
2321+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
22782322 req.Header.Add("X-Forwarded-For", "adsfljk29242as!!")
22792323 return req
22802324 }(),
@@ -2287,7 +2331,7 @@ func TestTrustedIPs(t *testing.T) {
22872331 reverseProxy: false,
22882332 realClientIPHeader: "X-Real-IP",
22892333 req: func() *http.Request {
2290− req, _ := http.NewRequest("GET", "/", nil)
2334+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
22912335 req.RemoteAddr = "adsfljk29242as!!"
22922336 return req
22932337 }(),
@@ -2383,12 +2427,12 @@ func Test_buildRoutesAllowlist(t *testing.T) {
23832427 },
23842428 expectedRoutes: []expectedAllowedRoute{
23852429 {
2386− method: "GET",
2430+ method: http.MethodGet,
23872431 negate: false,
23882432 regexString: "^/foo/bar",
23892433 },
23902434 {
2391− method: "POST",
2435+ method: http.MethodPost,
23922436 negate: false,
23932437 regexString: "^/baz/[0-9]+/thing",
23942438 },
@@ -2441,11 +2485,11 @@ func Test_buildRoutesAllowlist(t *testing.T) {
24412485 regexString: "^/baz/[0-9]+/thing/regex",
24422486 },
24432487 {
2444− method: "GET",
2488+ method: http.MethodGet,
24452489 regexString: "^/foo/bar",
24462490 },
24472491 {
2448− method: "POST",
2492+ method: http.MethodPost,
24492493 regexString: "^/baz/[0-9]+/thing",
24502494 },
24512495 {
@@ -2597,7 +2641,7 @@ func TestApiRoutes(t *testing.T) {
25972641
25982642 for _, tc := range testCases {
25992643 t.Run(tc.name, func(t *testing.T) {
2600− req, err := http.NewRequest("GET", tc.url, nil)
2644+ req, err := http.NewRequest(http.MethodGet, tc.url, nil)
26012645 req.Header.Set("Accept", tc.contentType)
26022646 assert.NoError(t, err)
26032647
@@ -2635,9 +2679,11 @@ func TestAllowedRequest(t *testing.T) {
26352679 }
26362680 opts.SkipAuthRegex = []string{
26372681 "^/skip/auth/regex$",
2682+ "^/public/.*/endpoint$",
26382683 }
26392684 opts.SkipAuthRoutes = []string{
26402685 "GET=^/skip/auth/routes/get",
2686+ "^/foo/.*/bar$",
26412687 }
26422688 err := validation.Validate(opts)
26432689 assert.NoError(t, err)
@@ -2654,25 +2700,37 @@ func TestAllowedRequest(t *testing.T) {
26542700 }{
26552701 {
26562702 name: "Regex GET allowed",
2657− method: "GET",
2703+ method: http.MethodGet,
26582704 url: "/skip/auth/regex",
26592705 allowed: true,
26602706 },
26612707 {
26622708 name: "Regex POST allowed ",
2663− method: "POST",
2709+ method: http.MethodPost,
26642710 url: "/skip/auth/regex",
26652711 allowed: true,
26662712 },
26672713 {
26682714 name: "Regex denied",
2669− method: "GET",
2715+ method: http.MethodGet,
26702716 url: "/wrong/denied",
26712717 allowed: false,
26722718 },
2719+ {
2720+ name: "Regex allowed with fragment-free path",
2721+ method: http.MethodGet,
2722+ url: "/public/legit/endpoint",
2723+ allowed: true,
2724+ },
2725+ {
2726+ name: "Regex denied when path contains encoded fragment suffix",
2727+ method: http.MethodGet,
2728+ url: "/public/secret%23/endpoint",
2729+ allowed: false,
2730+ },
26732731 {
26742732 name: "Route allowed",
2675− method: "GET",
2733+ method: http.MethodGet,
26762734 url: "/skip/auth/routes/get",
26772735 allowed: true,
26782736 },
@@ -2684,16 +2742,28 @@ func TestAllowedRequest(t *testing.T) {
26842742 },
26852743 {
26862744 name: "Route denied with wrong path",
2687− method: "GET",
2745+ method: http.MethodGet,
26882746 url: "/skip/auth/routes/wrong/path",
26892747 allowed: false,
26902748 },
26912749 {
26922750 name: "Route denied with wrong path and method",
2693− method: "POST",
2751+ method: http.MethodPost,
26942752 url: "/skip/auth/routes/wrong/path",
26952753 allowed: false,
26962754 },
2755+ {
2756+ name: "Route allowed with fragment-free path",
2757+ method: http.MethodGet,
2758+ url: "/foo/public/bar",
2759+ allowed: true,
2760+ },
2761+ {
2762+ name: "Route denied when path contains encoded fragment suffix",
2763+ method: http.MethodGet,
2764+ url: "/foo/secret%23/bar",
2765+ allowed: false,
2766+ },
26972767 }
26982768
26992769 for _, tc := range testCases {
@@ -2734,9 +2804,11 @@ func TestAllowedRequestWithForwardedUriHeader(t *testing.T) {
27342804 }
27352805 opts.SkipAuthRegex = []string{
27362806 "^/skip/auth/regex$",
2807+ "^/public/.*/endpoint$",
27372808 }
27382809 opts.SkipAuthRoutes = []string{
27392810 "GET=^/skip/auth/routes/get",
2811+ "^/foo/.*/bar$",
27402812 }
27412813 err := validation.Validate(opts)
27422814 assert.NoError(t, err)
@@ -2753,25 +2825,37 @@ func TestAllowedRequestWithForwardedUriHeader(t *testing.T) {
27532825 }{
27542826 {
27552827 name: "Regex GET allowed",
2756− method: "GET",
2828+ method: http.MethodGet,
27572829 url: "/skip/auth/regex",
27582830 allowed: true,
27592831 },
27602832 {
27612833 name: "Regex POST allowed ",
2762− method: "POST",
2834+ method: http.MethodPost,
27632835 url: "/skip/auth/regex",
27642836 allowed: true,
27652837 },
27662838 {
27672839 name: "Regex denied",
2768− method: "GET",
2840+ method: http.MethodGet,
27692841 url: "/wrong/denied",
27702842 allowed: false,
27712843 },
2844+ {
2845+ name: "Regex allowed with fragment-free path",
2846+ method: http.MethodGet,
2847+ url: "/public/legit/endpoint",
2848+ allowed: true,
2849+ },
2850+ {
2851+ name: "Regex denied when X-Forwarded-Uri contains an encoded fragment suffix",
2852+ method: http.MethodGet,
2853+ url: "/public/secret%23/endpoint",
2854+ allowed: false,
2855+ },
27722856 {
27732857 name: "Route allowed",
2774− method: "GET",
2858+ method: http.MethodGet,
27752859 url: "/skip/auth/routes/get",
27762860 allowed: true,
27772861 },
@@ -2783,22 +2867,35 @@ func TestAllowedRequestWithForwardedUriHeader(t *testing.T) {
27832867 },
27842868 {
27852869 name: "Route denied with wrong path",
2786− method: "GET",
2870+ method: http.MethodGet,
27872871 url: "/skip/auth/routes/wrong/path",
27882872 allowed: false,
27892873 },
27902874 {
27912875 name: "Route denied with wrong path and method",
2792− method: "POST",
2876+ method: http.MethodPost,
27932877 url: "/skip/auth/routes/wrong/path",
27942878 allowed: false,
27952879 },
2880+ {
2881+ name: "Route allowed with fragment-free path",
2882+ method: http.MethodGet,
2883+ url: "/foo/public/bar",
2884+ allowed: true,
2885+ },
2886+ {
2887+ name: "Route denied when X-Forwarded-Uri contains an encoded fragment suffix",
2888+ method: http.MethodGet,
2889+ url: "/foo/secret%23/bar",
2890+ allowed: false,
2891+ },
27962892 }
27972893
27982894 for _, tc := range testCases {
27992895 t.Run(tc.name, func(t *testing.T) {
28002896 req, err := http.NewRequest(tc.method, opts.ProxyPrefix+authOnlyPath, nil)
28012897 req.Header.Set("X-Forwarded-Uri", tc.url)
2898+ req.RemoteAddr = "127.0.0.1:4180"
28022899 assert.NoError(t, err)
28032900
28042901 rw := httptest.NewRecorder()
@@ -2813,6 +2910,43 @@ func TestAllowedRequestWithForwardedUriHeader(t *testing.T) {
28132910 }
28142911}
28152912
2913+func TestAllowedRequestWithForwardedUriHeaderRequiresTrustedProxy(t *testing.T) {
2914+ upstreamServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2915+ w.WriteHeader(200)
2916+ }))
2917+ t.Cleanup(upstreamServer.Close)
2918+
2919+ opts := baseTestOptions()
2920+ opts.ReverseProxy = true
2921+ opts.TrustedProxyIPs = []string{"127.0.0.1/32"}
2922+ opts.UpstreamServers = options.UpstreamConfig{
2923+ Upstreams: []options.Upstream{
2924+ {
2925+ ID: upstreamServer.URL,
2926+ Path: "/",
2927+ URI: upstreamServer.URL,
2928+ },
2929+ },
2930+ }
2931+ opts.SkipAuthRegex = []string{"^/skip/auth/regex$"}
2932+
2933+ err := validation.Validate(opts)
2934+ assert.NoError(t, err)
2935+
2936+ proxy, err := NewOAuthProxy(opts, func(_ string) bool { return true })
2937+ assert.NoError(t, err)
2938+
2939+ req, err := http.NewRequest(http.MethodGet, opts.ProxyPrefix+authOnlyPath, nil)
2940+ assert.NoError(t, err)
2941+ req.RemoteAddr = "192.0.2.10:4180"
2942+ req.Header.Set("X-Forwarded-Uri", "/skip/auth/regex")
2943+
2944+ rw := httptest.NewRecorder()
2945+ proxy.ServeHTTP(rw, req)
2946+
2947+ assert.Equal(t, 401, rw.Code)
2948+}
2949+
28162950func TestAllowedRequestNegateWithoutMethod(t *testing.T) {
28172951 upstreamServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
28182952 w.WriteHeader(200)
@@ -2852,37 +2986,37 @@ func TestAllowedRequestNegateWithoutMethod(t *testing.T) {
28522986 }{
28532987 {
28542988 name: "Some static file allowed",
2855− method: "GET",
2989+ method: http.MethodGet,
28562990 url: "/static/file.txt",
28572991 allowed: true,
28582992 },
28592993 {
28602994 name: "POST to contact form allowed",
2861− method: "POST",
2995+ method: http.MethodPost,
28622996 url: "/contact",
28632997 allowed: true,
28642998 },
28652999 {
28663000 name: "Regex POST allowed",
2867− method: "POST",
3001+ method: http.MethodPost,
28683002 url: "/api/public-entity",
28693003 allowed: true,
28703004 },
28713005 {
28723006 name: "Regex POST with trailing slash allowed",
2873− method: "POST",
3007+ method: http.MethodPost,
28743008 url: "/api/public-entity/",
28753009 allowed: true,
28763010 },
28773011 {
28783012 name: "Regex GET api route denied",
2879− method: "GET",
3013+ method: http.MethodGet,
28803014 url: "/api/users",
28813015 allowed: false,
28823016 },
28833017 {
28843018 name: "Regex POST api route denied",
2885− method: "POST",
3019+ method: http.MethodPost,
28863020 url: "/api/users",
28873021 allowed: false,
28883022 },
@@ -2952,37 +3086,37 @@ func TestAllowedRequestNegateWithMethod(t *testing.T) {
29523086 }{
29533087 {
29543088 name: "Some static file allowed",
2955− method: "GET",
3089+ method: http.MethodGet,
29563090 url: "/static/file.txt",
29573091 allowed: true,
29583092 },
29593093 {
29603094 name: "POST to contact form not allowed",
2961− method: "POST",
3095+ method: http.MethodPost,
29623096 url: "/contact",
29633097 allowed: false,
29643098 },
29653099 {
29663100 name: "Regex POST allowed",
2967− method: "POST",
3101+ method: http.MethodPost,
29683102 url: "/api/public-entity",
29693103 allowed: true,
29703104 },
29713105 {
29723106 name: "Regex POST with trailing slash allowed",
2973− method: "POST",
3107+ method: http.MethodPost,
29743108 url: "/api/public-entity/",
29753109 allowed: true,
29763110 },
29773111 {
29783112 name: "Regex GET api route denied",
2979− method: "GET",
3113+ method: http.MethodGet,
29803114 url: "/api/users",
29813115 allowed: false,
29823116 },
29833117 {
29843118 name: "Regex POST api route denied",
2985− method: "POST",
3119+ method: http.MethodPost,
29863120 url: "/api/users",
29873121 allowed: false,
29883122 },
@@ -3122,7 +3256,7 @@ func TestProxyAllowedGroups(t *testing.T) {
31223256 t.Fatal(err)
31233257 }
31243258
3125− test.req, _ = http.NewRequest("GET", fmt.Sprintf("/%s", tt.querystring), nil)
3259+ test.req, _ = http.NewRequest(http.MethodGet, fmt.Sprintf("/%s", tt.querystring), nil)
31263260
31273261 test.req.Header.Add("accept", applicationJSON)
31283262 err = test.SaveSession(session)
@@ -3266,7 +3400,7 @@ func TestAuthOnlyAllowedGroupsWithSkipMethods(t *testing.T) {
32663400 {
32673401 name: "UserWithGroupSkipAuthPreflight",
32683402 groups: []string{"a", "c"},
3269− method: "OPTIONS",
3403+ method: http.MethodOptions,
32703404 ip: "1.2.3.5:43670",
32713405 withSession: true,
32723406 expectedStatusCode: http.StatusAccepted,
@@ -3274,7 +3408,7 @@ func TestAuthOnlyAllowedGroupsWithSkipMethods(t *testing.T) {
32743408 {
32753409 name: "UserWithGroupTrustedIp",
32763410 groups: []string{"a", "c"},
3277− method: "GET",
3411+ method: http.MethodGet,
32783412 ip: "1.2.3.4:43670",
32793413 withSession: true,
32803414 expectedStatusCode: http.StatusAccepted,
@@ -3282,7 +3416,7 @@ func TestAuthOnlyAllowedGroupsWithSkipMethods(t *testing.T) {
32823416 {
32833417 name: "UserWithoutGroupSkipAuthPreflight",
32843418 groups: []string{"c"},
3285− method: "OPTIONS",
3419+ method: http.MethodOptions,
32863420 ip: "1.2.3.5:43670",
32873421 withSession: true,
32883422 expectedStatusCode: http.StatusForbidden,
@@ -3290,21 +3424,21 @@ func TestAuthOnlyAllowedGroupsWithSkipMethods(t *testing.T) {
32903424 {
32913425 name: "UserWithoutGroupTrustedIp",
32923426 groups: []string{"c"},
3293− method: "GET",
3427+ method: http.MethodGet,
32943428 ip: "1.2.3.4:43670",
32953429 withSession: true,
32963430 expectedStatusCode: http.StatusForbidden,
32973431 },
32983432 {
32993433 name: "UserWithoutSessionSkipAuthPreflight",
3300− method: "OPTIONS",
3434+ method: http.MethodOptions,
33013435 ip: "1.2.3.5:43670",
33023436 withSession: false,
33033437 expectedStatusCode: http.StatusAccepted,
33043438 },
33053439 {
33063440 name: "UserWithoutSessionTrustedIp",
3307− method: "GET",
3441+ method: http.MethodGet,
33083442 ip: "1.2.3.4:43670",
33093443 withSession: false,
33103444 expectedStatusCode: http.StatusAccepted,
@@ -3404,6 +3538,24 @@ func TestAuthOnlyAllowedEmailDomains(t *testing.T) {
34043538 querystring: "?allowed_email_domains=a.b.c.example.com,*.c.example.com",
34053539 expectedStatusCode: http.StatusAccepted,
34063540 },
3541+ {
3542+ name: "UserWithMultipleAtSignsExactDomain",
3543+ email: "attacker@evil.com@example.com",
3544+ querystring: "?allowed_email_domains=example.com",
3545+ expectedStatusCode: http.StatusForbidden,
3546+ },
3547+ {
3548+ name: "UserWithMultipleAtSignsWildcardDomain",
3549+ email: "attacker@evil.com@foo.example.com",
3550+ querystring: "?allowed_email_domains=*.example.com",
3551+ expectedStatusCode: http.StatusForbidden,
3552+ },
3553+ {
3554+ name: "UserWithMultipleAtSignsDotPrefixedDomain",
3555+ email: "attacker@evil.com@foo.example.com",
3556+ querystring: "?allowed_email_domains=.example.com",
3557+ expectedStatusCode: http.StatusForbidden,
3558+ },
34073559 }
34083560
34093561 for _, tc := range testCases {
@@ -3638,14 +3790,14 @@ func TestIdTokenPlaceholderInSignOut(t *testing.T) {
36383790
36393791 // Save the required session
36403792 rw := httptest.NewRecorder()
3641− req, _ := http.NewRequest("GET", "/", nil)
3793+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
36423794 err = proxy.sessionStore.Save(rw, req, session)
36433795 assert.NoError(t, err)
36443796
36453797 rw = httptest.NewRecorder()
36463798
36473799 rdUrl := url.QueryEscape("https://my-oidc-provider.example.com/sign_out_page?id_token_hint={id_token}&post_logout_redirect_uri=https://my-app.example.com/")
3648− req, _ = http.NewRequest("GET", "/oauth2/sign_out?rd="+rdUrl, nil)
3800+ req, _ = http.NewRequest(http.MethodGet, "/oauth2/sign_out?rd="+rdUrl, nil)
36493801 req = middlewareapi.AddRequestScope(req, &middlewareapi.RequestScope{
36503802 RequestID: "11111111-2222-4333-8444-555555555555",
36513803 Session: session,