Open platform to collect and prioritize feedback
Reject redirects with several leading slashes in OAuth token handler
Matt Roberts66ce64994357
diff --git a/app/handlers/oauth.go b/app/handlers/oauth.goindex 5aeceacae..dff349c29 100644--- a/app/handlers/oauth.go+++ b/app/handlers/oauth.go@@ -141,8 +141,10 @@ func sanitiseOAuthRedirect(c *web.Context, redirect string) string {return "/"}+ // Go parses "///evil.com" as a path with no host, but browsers skip any run of leading+ // slashes and treat what follows as the host, so a path must not start with "//".path := u.EscapedPath()- if !strings.HasPrefix(path, "/") {+ if !strings.HasPrefix(path, "/") || strings.HasPrefix(path, "//") {return "/"}diff --git a/app/handlers/oauth_test.go b/app/handlers/oauth_test.goindex 72c09eec3..d3358d80e 100644--- a/app/handlers/oauth_test.go+++ b/app/handlers/oauth_test.go@@ -486,7 +486,7 @@ func TestOAuthTokenHandler_ExistingUserAndProvider(t *testing.T) {server := mock.NewServer()code, response := server.- WithURL("http://demo.test.fider.io/oauth/facebook/token?code=123&redirect=/hello&handoff=" + newHandoff(app.FacebookProvider, "http://demo.test.fider.io", "MY_SESSION_ID")).+ WithURL("http://demo.test.fider.io/oauth/facebook/token?code=123&redirect=/hello&handoff="+newHandoff(app.FacebookProvider, "http://demo.test.fider.io", "MY_SESSION_ID")).OnTenant(mock.DemoTenant).AddCookie(web.CookieSessionName, "MY_SESSION_ID").AddParam("provider", app.FacebookProvider).@@ -537,7 +537,7 @@ func TestOAuthTokenHandler_NewUser(t *testing.T) {server := mock.NewServer()code, response := server.- WithURL("http://demo.test.fider.io/oauth/facebook/token?code=456&redirect=/hello&handoff=" + newHandoff(app.FacebookProvider, "http://demo.test.fider.io", "MY_SESSION_ID")).+ WithURL("http://demo.test.fider.io/oauth/facebook/token?code=456&redirect=/hello&handoff="+newHandoff(app.FacebookProvider, "http://demo.test.fider.io", "MY_SESSION_ID")).OnTenant(mock.DemoTenant).AddCookie(web.CookieSessionName, "MY_SESSION_ID").AddParam("provider", app.FacebookProvider).@@ -584,7 +584,7 @@ func TestOAuthTokenHandler_NewUserWithoutEmail(t *testing.T) {})code, response := server.- WithURL("http://demo.test.fider.io/oauth/facebook/token?code=798&redirect=/&handoff=" + newHandoff(app.FacebookProvider, "http://demo.test.fider.io", "MY_SESSION_ID")).+ WithURL("http://demo.test.fider.io/oauth/facebook/token?code=798&redirect=/&handoff="+newHandoff(app.FacebookProvider, "http://demo.test.fider.io", "MY_SESSION_ID")).OnTenant(mock.DemoTenant).AddParam("provider", app.FacebookProvider).AddCookie(web.CookieSessionName, "MY_SESSION_ID").@@ -640,7 +640,7 @@ func TestOAuthTokenHandler_ExistingUser_WithoutEmail(t *testing.T) {})code, response := server.- WithURL("http://demo.test.fider.io/oauth/facebook/token?code=456&redirect=/&handoff=" + newHandoff(app.FacebookProvider, "http://demo.test.fider.io", "MY_SESSION_ID")).+ WithURL("http://demo.test.fider.io/oauth/facebook/token?code=456&redirect=/&handoff="+newHandoff(app.FacebookProvider, "http://demo.test.fider.io", "MY_SESSION_ID")).OnTenant(mock.DemoTenant).AddParam("provider", app.FacebookProvider).AddCookie(web.CookieSessionName, "MY_SESSION_ID").@@ -691,7 +691,7 @@ func TestOAuthTokenHandler_ExistingUser_NewProvider(t *testing.T) {server := mock.NewServer()code, response := server.- WithURL("http://demo.test.fider.io/oauth/google/token?code=123&redirect=/&handoff=" + newHandoff(app.GoogleProvider, "http://demo.test.fider.io", "MY_SESSION_ID")).+ WithURL("http://demo.test.fider.io/oauth/google/token?code=123&redirect=/&handoff="+newHandoff(app.GoogleProvider, "http://demo.test.fider.io", "MY_SESSION_ID")).OnTenant(mock.DemoTenant).AddParam("provider", app.GoogleProvider).AddCookie(web.CookieSessionName, "MY_SESSION_ID").@@ -899,7 +899,16 @@ func TestOAuthTokenHandler_ExpiredHandoff(t *testing.T) {func TestOAuthTokenHandler_OpenRedirect(t *testing.T) {RegisterT(t)- for _, redirect := range []string{"http://evil.com/x", "//evil.com/x", "https://feedback.theavengers.com.evil.com/x"} {+ // Browsers read any run of leading slashes, or a backslash, as the start of a host.+ for redirect, location := range map[string]string{+ "http://evil.com/x": "/",+ "//evil.com/x": "/",+ "///evil.com/x": "/",+ "////evil.com/x": "/",+ "https://feedback.theavengers.com.evil.com/x": "/",+ "/\\evil.com/x": "/%5Cevil.com/x",+ "/%2F/evil.com/x": "/%2F/evil.com/x",+ } {code, response := mock.NewServer().WithURL("http://feedback.theavengers.com/oauth/facebook/token?redirect="+url.QueryEscape(redirect)).OnTenant(mock.AvengersTenant).@@ -909,7 +918,7 @@ func TestOAuthTokenHandler_OpenRedirect(t *testing.T) {Execute(handlers.OAuthToken())Expect(code).Equals(http.StatusTemporaryRedirect)- Expect(response.Header().Get("Location")).Equals("/")+ Expect(response.Header().Get("Location")).Equals(location)}}