Skip to content

Commit d8ea0c6

Browse files
authored
Merge pull request #247 from authorizerdev/fix/same-site-cookie
fix(server): use sameSite as lax by default for app cookie
2 parents 536fd87 + f5323e0 commit d8ea0c6

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

server/cookie/cookie.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,18 @@ func SetSession(gc *gin.Context, sessionID string) {
2929
domain = "." + domain
3030
}
3131

32+
// Use sameSite = lax by default
33+
// Since app cookie can come from cross site it becomes important to set this in lax mode.
34+
// Example person using custom UI on their app domain and making request to authorizer domain.
35+
// For more information check:
36+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite
37+
// https://github.com/gin-gonic/gin/blob/master/context.go#L86
38+
// TODO add ability to sameSite = none / strict from dashboard
39+
gc.SetSameSite(http.SameSiteLaxMode)
40+
3241
// TODO allow configuring from dashboard
3342
year := 60 * 60 * 24 * 365
3443

35-
gc.SetSameSite(http.SameSiteNoneMode)
3644
gc.SetCookie(constants.AppCookieName+"_session", sessionID, year, "/", host, secure, httpOnly)
3745
gc.SetCookie(constants.AppCookieName+"_session_domain", sessionID, year, "/", domain, secure, httpOnly)
3846
}

server/parsers/url.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
)
1212

1313
// GetHost returns hostname from request context
14-
// if X-Authorizer-URL header is set it is given highest priority
15-
// if EnvKeyAuthorizerURL is set it is given second highest priority.
14+
// if EnvKeyAuthorizerURL is set it is given highest priority.
15+
// if X-Authorizer-URL header is set it is given second highest priority
1616
// if above 2 are not set the requesting host name is used
1717
func GetHost(c *gin.Context) string {
1818
authorizerURL, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyAuthorizerURL)

0 commit comments

Comments
 (0)