[MM-41022] - Fix panic when AllowCookiesSubdomain setting is false (#19339)

* [MM-41022] - Cloud: Panic after log in when AllowCookiesSubdomain setting is false

* remove print

* improvement

* remove configration setting from flow

* fix tests

* feedback impl

* feedback impl
Этот коммит содержится в:
Allan Guwatudde
2022-01-17 18:50:40 +03:00
коммит произвёл GitHub
родитель 0a06b3e808
Коммит ee92bda912
2 изменённых файлов: 42 добавлений и 7 удалений

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

@@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"net/http"
"net/url"
"os"
"strconv"
"strings"
@@ -245,21 +246,35 @@ func (a *App) AttachCloudSessionCookie(c *request.Context, w http.ResponseWriter
}
maxAge := *a.Config().ServiceSettings.SessionLengthWebInDays * 60 * 60 * 24
domain := a.GetCookieDomain()
subpath, _ := utils.GetSubpathFromConfig(a.Config())
expiresAt := time.Unix(model.GetMillis()/1000+int64(maxAge), 0)
var val string
domain := ""
if siteURL, err := url.Parse(a.GetSiteURL()); err == nil {
domain = siteURL.Hostname()
}
if domain == "" {
return
}
var workspaceName string
if strings.Contains(domain, "localhost") {
val = "localhost"
workspaceName = "localhost"
} else {
val = strings.SplitN(domain, ".", 2)[0]
// ensure we have a format for a cloud workspace url i.e. example.cloud.mattermost.com
if len(strings.Split(domain, ".")) != 4 {
return
}
workspaceName = strings.SplitN(domain, ".", 2)[0]
domain = strings.SplitN(domain, ".", 3)[2]
domain = "." + domain
}
cookie := &http.Cookie{
Name: model.SessionCookieCloudUrl,
Value: val,
Value: workspaceName,
Path: subpath,
MaxAge: maxAge,
Expires: expiresAt,
@@ -269,6 +284,7 @@ func (a *App) AttachCloudSessionCookie(c *request.Context, w http.ResponseWriter
}
http.SetCookie(w, cookie)
}
func (a *App) AttachSessionCookies(c *request.Context, w http.ResponseWriter, r *http.Request) {