Skip to content

Commit

Permalink
fix: disallow external url during oauth login
Browse files Browse the repository at this point in the history
  • Loading branch information
goenning committed Mar 24, 2023
1 parent cce8efa commit b5c626b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/handlers/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions app/handlers/oauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down

0 comments on commit b5c626b

Please sign in to comment.