File tree Expand file tree Collapse file tree 6 files changed +30
-10
lines changed Expand file tree Collapse file tree 6 files changed +30
-10
lines changed Original file line number Diff line number Diff line change 2323 LATEST : " true"
2424 GO111MODULE : " on"
2525
26+ " 1.14 " :
27+ << : *test
28+ docker :
29+ - image : circleci/golang:1.14
30+
31+ " 1.13 " :
32+ << : *test
33+ docker :
34+ - image : circleci/golang:1.13
35+
2636 " 1.12 " :
2737 << : *test
2838 docker :
@@ -58,6 +68,8 @@ workflows:
5868 build :
5969 jobs :
6070 - " latest"
71+ - " 1.14"
72+ - " 1.13"
6173 - " 1.12"
6274 - " 1.11"
6375 - " 1.10"
Original file line number Diff line number Diff line change @@ -62,9 +62,10 @@ type SameSiteMode int
6262
6363// SameSite options
6464const (
65- // SameSiteDefaultMode sets an invalid SameSite header which defaults to
66- // 'Lax' in most browsers, but may cause some browsers to ignore the cookie
67- // entirely.
65+ // SameSiteDefaultMode sets the `SameSite` cookie attribute, which is
66+ // invalid in some older browsers due to changes in the SameSite spec. These
67+ // browsers will not send the cookie to the server.
68+ // csrf uses SameSiteLaxMode (SameSite=Lax) as the default as of v1.7.0+
6869 SameSiteDefaultMode SameSiteMode = iota + 1
6970 SameSiteLaxMode
7071 SameSiteStrictMode
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ module github.com/gorilla/csrf
22
33require (
44 github.com/gorilla/securecookie v1.1.1
5- github.com/pkg/errors v0.8.0
5+ github.com/pkg/errors v0.9.1
66)
77
88go 1.13
Original file line number Diff line number Diff line change @@ -2,3 +2,5 @@ github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyC
22github.com/gorilla/securecookie v1.1.1 /go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4 =
33github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw =
44github.com/pkg/errors v0.8.0 /go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0 =
5+ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4 =
6+ github.com/pkg/errors v0.9.1 /go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0 =
Original file line number Diff line number Diff line change @@ -152,6 +152,10 @@ func parseOptions(h http.Handler, opts ...Option) *csrf {
152152 cs .opts .Secure = true
153153 cs .opts .HttpOnly = true
154154
155+ // Set SameSite=Lax by default, allowing the CSRF cookie to only be sent on
156+ // top-level navigations.
157+ cs .opts .SameSite = SameSiteLaxMode
158+
155159 // Default; only override this if the package user explicitly calls MaxAge(0)
156160 cs .opts .MaxAge = defaultAge
157161
Original file line number Diff line number Diff line change @@ -160,9 +160,9 @@ func TestSameSizeSet(t *testing.T) {
160160 }
161161}
162162
163- // TestSamesiteBackwardsCompat tests that the default set of options do not set
164- // any SameSite attribute .
165- func TestSamesiteBackwardsCompat (t * testing.T ) {
163+ // TestSameSiteDefault tests that the default set of options
164+ // set SameSite=Lax on the CSRF cookie .
165+ func TestSameSiteDefaultLaxMode (t * testing.T ) {
166166 s := http .NewServeMux ()
167167 s .HandleFunc ("/" , testHandler )
168168
@@ -182,10 +182,11 @@ func TestSamesiteBackwardsCompat(t *testing.T) {
182182
183183 cookie := rr .Header ().Get ("Set-Cookie" )
184184 if cookie == "" {
185- t .Fatalf ("cookie not get set-cookie header: got headers %v" , rr .Header ())
185+ t .Fatalf ("cookie not get Set-Cookie header: got headers %v" , rr .Header ())
186186 }
187187
188- if strings .Contains (cookie , "SameSite" ) {
189- t .Fatalf ("cookie should not contain the substring 'SameSite' by default, but did: %q" , cookie )
188+ sameSiteLax := "SameSite=Lax"
189+ if ! strings .Contains (cookie , sameSiteLax ) {
190+ t .Fatalf ("cookie should contain %q by default: got %s" , sameSiteLax , cookie )
190191 }
191192}
You can’t perform that action at this time.
0 commit comments