Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

fix: disallow external url during oauth login

goenningb5c626b82944
diff --git a/app/handlers/oauth.go b/app/handlers/oauth.go
index 959d24f6c..4a2ffd959 100644
--- a/app/handlers/oauth.go
+++ b/app/handlers/oauth.go
@@ -239,6 +239,8 @@ func SignInByOAuth() web.HandlerFunc {
if redirect == "" {
redirect = c.BaseURL()
+ } else if !strings.HasPrefix(redirect, c.BaseURL()) {
+ return c.Forbidden()
}
redirectURL, _ := url.ParseRequestURI(redirect)
diff --git a/app/handlers/oauth_test.go b/app/handlers/oauth_test.go
index c185aaf02..51d795812 100644
--- a/app/handlers/oauth_test.go
+++ b/app/handlers/oauth_test.go
@@ -45,6 +45,21 @@ func TestSignInByOAuthHandler(t *testing.T) {
RegisterT(t)
bus.Init(&oauth.Service{})
+ server := mock.NewServer()
+ code, _ := server.
+ AddParam("provider", app.FacebookProvider).
+ AddCookie(web.CookieSessionName, "MY_SESSION_ID").
+ WithURL("http://avengers.test.fider.io/oauth/facebook?redirect=http://evil.com").
+ Use(middlewares.Session()).
+ Execute(handlers.SignInByOAuth())
+
+ Expect(code).Equals(http.StatusForbidden)
+}
+
+func TestSignInByOAuthHandler_InvalidURL(t *testing.T) {
+ RegisterT(t)
+ bus.Init(&oauth.Service{})
+
server := mock.NewServer()
code, response := server.
AddParam("provider", app.FacebookProvider).