CRSF with Sec-Fetch-Site checks#2858
Merged
aldas merged 2 commits intolabstack:masterfrom Dec 29, 2025
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2858 +/- ##
==========================================
+ Coverage 93.25% 93.51% +0.26%
==========================================
Files 39 42 +3
Lines 4652 4287 -365
==========================================
- Hits 4338 4009 -329
+ Misses 218 159 -59
- Partials 96 119 +23 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
Author
|
NB: in v4 we fall back to legacy token when Sec-Fetch-Site = same-site. In v5 same-site will be blocked as default behavior. blocking same-site would be probably breaking change for applications that deal with requests from sub-domains. e.Use(middleware.CSRFWithConfig(middleware.CSRFConfig{
TrustedOrigins: []string{"https://example.com", "https://subdomain.example.com"},
// or custom check when request is state-changing and Sec-Fetch-Site is `cross-site` or `same-site`
AllowSecFetchSiteFunc: func(c echo.Context) (bool, error) {
return false, echo.NewHTTPError(http.StatusForbidden, "request blocked by CSRF")
// return true, nil // allows CSRF request through
// return false, nil // falls back to legacy token logic
},
})) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
From: #2855
Note to self: Hackernews had this blog post posted.
see https://github.com/golang/go/blob/master/src/net/http/csrf.go which was introduced in GO 1.25