Skip to content

Commit d0f9d1e

Browse files
committed
CRSF with Sec-Fetch-Site=same-site falls back to legacy token
1 parent f3fc618 commit d0f9d1e

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

middleware/csrf.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,13 @@ func (config CSRFConfig) checkSecFetchSiteRequest(c echo.Context) (bool, error)
291291
}
292292
// we are here when request is state-changing and `cross-site` or `same-site`
293293

294-
// Note: if you want to allow `same-site` use config.TrustedOrigins or `config.AllowSecFetchSiteFunc`
294+
// Note: if you want to block `same-site` use config.TrustedOrigins or `config.AllowSecFetchSiteFunc`
295295
if config.AllowSecFetchSiteFunc != nil {
296296
return config.AllowSecFetchSiteFunc(c)
297297
}
298298

299299
if secFetchSite == "same-site" {
300-
return false, echo.NewHTTPError(http.StatusForbidden, "same-site request blocked by CSRF")
300+
return false, nil // fall back to legacy token
301301
}
302302
return false, echo.NewHTTPError(http.StatusForbidden, "cross-site request blocked by CSRF")
303303
}

middleware/csrf_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ func TestCSRFConfig_checkSecFetchSiteRequest(t *testing.T) {
559559
whenMethod: http.MethodPost,
560560
whenSecFetchSite: "same-site",
561561
expectAllow: false,
562-
expectErr: `code=403, message=same-site request blocked by CSRF`,
562+
expectErr: ``,
563563
},
564564
{
565565
name: "ok, unsafe POST + same-origin passes",
@@ -617,7 +617,7 @@ func TestCSRFConfig_checkSecFetchSiteRequest(t *testing.T) {
617617
whenMethod: http.MethodPut,
618618
whenSecFetchSite: "same-site",
619619
expectAllow: false,
620-
expectErr: `code=403, message=same-site request blocked by CSRF`,
620+
expectErr: ``,
621621
},
622622
{
623623
name: "nok, unsafe DELETE + cross-site is blocked",
@@ -633,7 +633,7 @@ func TestCSRFConfig_checkSecFetchSiteRequest(t *testing.T) {
633633
whenMethod: http.MethodDelete,
634634
whenSecFetchSite: "same-site",
635635
expectAllow: false,
636-
expectErr: `code=403, message=same-site request blocked by CSRF`,
636+
expectErr: ``,
637637
},
638638
{
639639
name: "nok, unsafe PATCH + cross-site is blocked",

0 commit comments

Comments
 (0)