Skip to content

Commit 2cad944

Browse files
zmb3github-actions
authored andcommitted
Explicitly set the session cookie to SameSite=Lax
Prior to this change, we were not explicitly setting the SameSite mode for our session cookie, which leaves the behavior up to the browser. Chromium-based browsers have been defaulting to SameSite=Lax since Chrome 80 in February 2020, so this is not a behavior change but rather locking in today's behavior and being explicit about it. Note that this is for Teleport's session cookie only. App session cookies remain using SameSite=None because the proxied app may itself be using SSO, and we need the app session cookie to make its way through SSO redirects.
1 parent 10f7868 commit 2cad944

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

lib/web/session/cookie.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func SetCookie(w http.ResponseWriter, user, sid string) error {
6767
Path: "/",
6868
HttpOnly: true,
6969
Secure: true,
70+
SameSite: http.SameSiteLaxMode,
7071
}
7172
http.SetCookie(w, c)
7273
return nil
@@ -80,6 +81,7 @@ func ClearCookie(w http.ResponseWriter) {
8081
Path: "/",
8182
HttpOnly: true,
8283
Secure: true,
84+
SameSite: http.SameSiteLaxMode,
8385
})
8486
}
8587

lib/web/session/cookie_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func TestCookies(t *testing.T) {
4848
require.Len(t, setCookies, 2)
4949

5050
// SetCookie will store the encoded session in the cookie
51-
require.Equal(t, "__Host-session=7b2275736572223a226c6c616d61222c22736964223a223938373635227d; Path=/; HttpOnly; Secure", setCookies[0])
51+
require.Equal(t, "__Host-session=7b2275736572223a226c6c616d61222c22736964223a223938373635227d; Path=/; HttpOnly; Secure; SameSite=Lax", setCookies[0])
5252
// ClearCookie will add an entry with the cookie value cleared out
53-
require.Equal(t, "__Host-session=; Path=/; HttpOnly; Secure", setCookies[1])
53+
require.Equal(t, "__Host-session=; Path=/; HttpOnly; Secure; SameSite=Lax", setCookies[1])
5454
}

0 commit comments

Comments
 (0)