@@ -51,6 +51,7 @@ type OAuthProxy struct {
51
51
CookieHttpOnly bool
52
52
CookieExpire time.Duration
53
53
CookieRefresh time.Duration
54
+ CookieSameSite string
54
55
Validator func (string ) bool
55
56
56
57
RobotsPath string
@@ -236,7 +237,7 @@ func NewOAuthProxy(opts *Options, validator func(string) bool) *OAuthProxy {
236
237
refresh = fmt .Sprintf ("after %s" , opts .CookieRefresh )
237
238
}
238
239
239
- log .Printf ("Cookie settings: name:%s secure(https):%v httponly:%v expiry:%s domain:%s refresh:%s" , opts .CookieName , opts .CookieSecure , opts .CookieHttpOnly , opts .CookieExpire , domain , refresh )
240
+ log .Printf ("Cookie settings: name:%s secure(https):%v httponly:%v expiry:%s domain:%s samesite:%s refresh:%s" , opts .CookieName , opts .CookieSecure , opts .CookieHttpOnly , opts .CookieExpire , domain , opts . CookieSameSite , refresh )
240
241
241
242
var cipher * cookie.Cipher
242
243
if opts .PassAccessToken || (opts .CookieRefresh != time .Duration (0 )) {
@@ -260,6 +261,7 @@ func NewOAuthProxy(opts *Options, validator func(string) bool) *OAuthProxy {
260
261
CookieHttpOnly : opts .CookieHttpOnly ,
261
262
CookieExpire : opts .CookieExpire ,
262
263
CookieRefresh : opts .CookieRefresh ,
264
+ CookieSameSite : opts .CookieSameSite ,
263
265
Validator : validator ,
264
266
265
267
RobotsPath : "/robots.txt" ,
@@ -379,6 +381,7 @@ func (p *OAuthProxy) makeCookie(req *http.Request, name string, value string, ex
379
381
HttpOnly : p .CookieHttpOnly ,
380
382
Secure : p .CookieSecure ,
381
383
Expires : now .Add (expiration ),
384
+ SameSite : parseSameSite (p .CookieSameSite ),
382
385
}
383
386
}
384
387
@@ -858,3 +861,19 @@ func (p *OAuthProxy) CheckRequestAuth(req *http.Request) (*providers.SessionStat
858
861
// handle advanced validation
859
862
return p .provider .ValidateRequest (req )
860
863
}
864
+
865
+ // Parse a valid http.SameSite value from a user supplied string for use of making cookies.
866
+ func parseSameSite (v string ) http.SameSite {
867
+ switch v {
868
+ case "lax" :
869
+ return http .SameSiteLaxMode
870
+ case "strict" :
871
+ return http .SameSiteStrictMode
872
+ case "none" :
873
+ return http .SameSiteNoneMode
874
+ case "" :
875
+ return http .SameSiteDefaultMode
876
+ default :
877
+ panic (fmt .Sprintf ("Invalid value for SameSite: %s" , v ))
878
+ }
879
+ }
0 commit comments