So that it does not unnecessarily leak over clear text connections.
This commit is contained in:
@@ -108,10 +108,22 @@ func basicAuthAndSessionMiddleware(cookieName string, guiCfg config.GUIConfigura
|
|||||||
sessionsMut.Lock()
|
sessionsMut.Lock()
|
||||||
sessions[sessionid] = true
|
sessions[sessionid] = true
|
||||||
sessionsMut.Unlock()
|
sessionsMut.Unlock()
|
||||||
|
|
||||||
|
// Best effort detection of whether the connection is HTTPS --
|
||||||
|
// either directly to us, or as used by the client towards a reverse
|
||||||
|
// proxy who sends us headers.
|
||||||
|
connectionIsHTTPS := r.TLS != nil ||
|
||||||
|
strings.ToLower(r.Header.Get("x-forwarded-proto")) == "https" ||
|
||||||
|
strings.Contains(strings.ToLower(r.Header.Get("forwarded")), "proto=https")
|
||||||
|
// If the connection is HTTPS, or *should* be HTTPS, set the Secure
|
||||||
|
// bit in cookies.
|
||||||
|
useSecureCookie := connectionIsHTTPS || guiCfg.UseTLS()
|
||||||
|
|
||||||
http.SetCookie(w, &http.Cookie{
|
http.SetCookie(w, &http.Cookie{
|
||||||
Name: cookieName,
|
Name: cookieName,
|
||||||
Value: sessionid,
|
Value: sessionid,
|
||||||
MaxAge: 0,
|
MaxAge: 0,
|
||||||
|
Secure: useSecureCookie,
|
||||||
})
|
})
|
||||||
|
|
||||||
emitLoginAttempt(true, username, r.RemoteAddr, evLogger)
|
emitLoginAttempt(true, username, r.RemoteAddr, evLogger)
|
||||||
|
|||||||
Reference in New Issue
Block a user