-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Fix #1523 by adding SameSite mode for CSRF settings #1524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1524 +/- ##
==========================================
+ Coverage 85.77% 85.89% +0.12%
==========================================
Files 29 29
Lines 2017 2021 +4
==========================================
+ Hits 1730 1736 +6
+ Misses 181 180 -1
+ Partials 106 105 -1
Continue to review full report at Codecov.
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hey, guys, why this request was closed? The problem is still here and should be fixed. |
Please reopen this PR - this solves a real issue. |
@@ -157,6 +165,9 @@ func CSRFWithConfig(config CSRFConfig) echo.MiddlewareFunc { | |||
if config.CookieDomain != "" { | |||
cookie.Domain = config.CookieDomain | |||
} | |||
if config.CookieSameSite != http.SameSiteDefaultMode { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The article on the issue say this:
Cookies with SameSite=None must also specify Secure, meaning they require a secure context.
So maybe it could be good to set cookie.Secure=true when SameSite=None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pafuent Maybe you can correct the testing strategy to take at least GO version 1.13 as a basis?
The http.SameSiteNoneMode constant appeared only in 1.13 version of GO(golang/go#32546), which is why GitHub Actions throws an error when checking: dc147d9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would mean this is a breaking change, as for vecho 4 we still consider Go v1.12 supported.
Do we rely on the actual implementation of SameSiteNoneMode in Golang, er just using the const for comparison?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lammel Are you suggesting to declare local constants that will be analogous in GoLang?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is what I meant. Go v1.12 will not have any changes in that regard anymore.
So in case we do not rely an additional functionality other than the constant I would prefer to do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, there will be a conflict.
The passed value in the config (config.CookieSameSite
) is will be set as cookie.SameSite
. Cookie, in turn, is a http.Cookie
structure and an attempt to set a value from a local constant will result in an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I'm missing something but maybe we can do something like this:
package main
import (
"fmt"
)
type SameSite int
const (
SameSiteDefaultMode SameSite = iota + 1
SameSiteLaxMode
SameSiteStrictMode
)
const (
SameSiteNoneMode SameSite = SameSiteStrictMode + 1
)
func main() {
var ss SameSite
ss = SameSiteLaxMode
fmt.Println(ss)
ss = SameSiteNoneMode
fmt.Println(ss)
}
The tricky part is how to write it in order to select our version of the constant or the Go 1.13.
One option is to use build constraints. So only for Go 1.12 you define an Echo constant SameSiteDefaultMode SameSite with a value equal to 4, for all the other versions, you define the same constant but equal to http.SameSiteDefaultMode
Something like this (please test it, I didn't had the time to do it)
samesite.go
// +build !go1.12
package middleware
import (
"net/http"
)
const (
SameSiteNoneMode http.SameSite = http.SameSiteNoneMode
)
samesite_1_12.go
// +build go1.12
package middleware
import (
"net/http"
)
const (
SameSiteNoneMode http.SameSite = 4
)
Thanks for the work getting this in! |
Workaround for Go 1.12 as suggested by @aldas has been added to master so tests should be fine by now. |
No description provided.