Skip to content

Commit 6e8d9b4

Browse files
committed
1. support cookie max age configuration
2. set cookie same site default as `lax`
1 parent d3f623f commit 6e8d9b4

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

cmd/erda-server/bootstrap.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,10 @@ openapi-interceptor-csrf:
139139
cookie_name: "OPENAPI-CSRF-TOKEN"
140140
cookie_domain: "${CSRF_COOKIE_DOMAIN}"
141141
cookie_path: "/"
142-
cookie_max_age: "12h"
142+
cookie_max_age: "${COOKIE_MAX_AGE:12h}"
143143
token_lookup: "header:OPENAPI-CSRF-TOKEN"
144144
cookie_http_only: true
145+
cookie_same_site: "${COOKIE_SAME_SITE:2}"
145146
openapi-interceptor-filter-client-header:
146147
order: 11
147148
openapi-interceptor-auth-session-compatibility:

internal/core/openapi/openapi-ng/interceptors/csrf/csrf.go

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ type config struct {
4444
CookiePath string `file:"cookie_path" default:"/" desc:"path of the CSRF cookie. optional."`
4545
CookieMaxAge time.Duration `file:"cookie_max_age" default:"24h" desc:"max age of the CSRF cookie. optional."`
4646
CookieHTTPOnly bool `file:"cookie_http_only" default:"false" desc:"indicates if CSRF cookie is HTTP only. optional."`
47+
48+
// CookieSameSite default set to 2, which is `lax`, more options see https://github.com/golang/go/blob/619b419a4b1506bde1aa7e833898f2f67fd0e83e/src/net/http/cookie.go#L52-L57
49+
CookieSameSite http.SameSite `file:"cookie_same_site" default:"2" desc:"indicates if CSRF cookie is SameSite. optional."`
4750
}
4851

4952
type (
@@ -250,6 +253,7 @@ func (p *provider) setCSRFCookie(rw http.ResponseWriter, r *http.Request, token
250253
cookie.Expires = time.Now().Add(p.Cfg.CookieMaxAge)
251254
cookie.Secure = p.getScheme(r) == "https"
252255
cookie.HttpOnly = p.Cfg.CookieHTTPOnly
256+
cookie.SameSite = p.Cfg.CookieSameSite
253257
http.SetCookie(rw, cookie)
254258
return token
255259
}

0 commit comments

Comments
 (0)