Skip to content
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

Add ability to set SameSite attribute of cookie #15

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion csrf.go
Expand Up @@ -137,6 +137,8 @@ type Options struct {
SetCookie bool
// Set the Secure flag to true on the cookie.
Secure bool
// Set the SameSite attribute to Lax (false) or Strict (true)
SameSite bool
// Disallow Origin appear in request header.
Origin bool
// The function called when Validate fails.
Expand Down Expand Up @@ -243,7 +245,7 @@ func Generate(options ...Options) macaron.Handler {
// FIXME: actionId.
x.Token = GenerateToken(x.Secret, x.ID, "POST")
if opt.SetCookie {
ctx.SetCookie(opt.Cookie, x.Token, 0, opt.CookiePath, opt.CookieDomain, opt.Secure, opt.CookieHttpOnly, time.Now().AddDate(0, 0, 1))
ctx.SetCookie(opt.Cookie, x.Token, 0, opt.CookiePath, opt.CookieDomain, opt.Secure, opt.CookieHttpOnly, time.Now().AddDate(0, 0, 1), opt.SameSite)
}
}

Expand Down
5 changes: 2 additions & 3 deletions go.mod
Expand Up @@ -3,8 +3,7 @@ module github.com/go-macaron/csrf
go 1.12

require (
github.com/go-macaron/session v0.0.0-20190805070824-1a3cdc6f5659
github.com/go-macaron/session v1.0.0
github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337
github.com/unknwon/com v0.0.0-20190804042917-757f69c95f3e
gopkg.in/macaron.v1 v1.3.4
gopkg.in/macaron.v1 v1.3.4 // TODO: update once go-macaron/macaron#206 is merged
)