Change cookie oidc_nonce to SameSite=None.

https://github.com/matrix-org/dendrite/issues/1297#issuecomment-1139357227
This commit is contained in:
Tommie Gannert 2022-05-27 09:58:31 +02:00
parent 83bac7df36
commit 618e18f259

View file

@ -20,6 +20,7 @@ import (
"fmt"
"net/http"
"net/url"
"path"
"strings"
"time"
@ -89,14 +90,20 @@ func SSORedirect(
util.GetLogger(ctx).Infof("SSO redirect to %s.", u)
resp := util.RedirectResponse(u)
resp.Headers["Set-Cookie"] = (&http.Cookie{
cookie := &http.Cookie{
Name: "oidc_nonce",
Value: nonce,
Path: "/",
Path: path.Dir(callbackURL.Path),
Expires: time.Now().Add(10 * time.Minute),
Secure: callbackURL.Scheme != "http",
SameSite: http.SameSiteStrictMode,
}).String()
SameSite: http.SameSiteNoneMode,
}
if !cookie.Secure {
// SameSite=None requires Secure, so we might as well remove
// it. See https://blog.chromium.org/2019/10/developers-get-ready-for-new.html.
cookie.SameSite = http.SameSiteDefaultMode
}
resp.Headers["Set-Cookie"] = cookie.String()
return resp
}