Convert URLs to fully-qualified for HTTP redirects (#19020)

* Convert URLs to fully-qualified for HTTP redirects

* forgot the tests
Этот коммит содержится в:
Lev
2021-11-23 08:51:25 -08:00
коммит произвёл GitHub
родитель 8440a754b4
Коммит 03f43d7ae5
3 изменённых файлов: 29 добавлений и 6 удалений

Просмотреть файл

@@ -289,6 +289,7 @@ func completeOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
hasRedirectURL = redirectURL != ""
}
}
redirectURL = fullyQualifiedRedirectURL(c.GetSiteURLHeader(), redirectURL)
renderError := func(err *model.AppError) {
if isMobile && hasRedirectURL {
@@ -341,11 +342,6 @@ func completeOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
return
} else { // For web
c.App.AttachSessionCookies(c.AppContext, w, r)
// If no redirect url is passed, get the default one
if !hasRedirectURL {
redirectURL = c.GetSiteURLHeader()
}
}
}
@@ -438,3 +434,15 @@ func signupWithOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, authURL, http.StatusFound)
}
func fullyQualifiedRedirectURL(siteURLPrefix, targetURL string) string {
parsed, _ := url.Parse(targetURL)
if parsed == nil || parsed.Scheme != "" || parsed.Host != "" {
return targetURL
}
if targetURL != "" && targetURL[0] != '/' {
targetURL = "/" + targetURL
}
return siteURLPrefix + targetURL
}