Skip to content

Go pkg to set SameSite=None cookie attribute safely (handle incompatible browsers)

License

Notifications You must be signed in to change notification settings

VojtechVitek/samesite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Set SameSite=None cookie attribute safely in Golang

GoDoc

Set SameSite=None cookie attribute safely, so it's handled well by all incompatible browsers, as listed at https://www.chromium.org/updates/same-site/incompatible-clients.

Example:

func SetCookieHandler(w http.ResponseWriter, r *http.Request) {
	cookie := http.Cookie{
		Name:     "name",
		Domain:   "example.com",
		Path:     "/",
		Secure:   true,                         // HTTPS only.
		SameSite: samesite.None(r.UserAgent()), // Set SameSite=None unless browser is incompatible.
		HttpOnly: true,
		MaxAge:   3600 * 24 * 365,
		Expires:  time.Now().AddDate(1, 0, 0),
		Value:    "value",
	}

	http.SetCookie(w, &cookie)
}

About

Go pkg to set SameSite=None cookie attribute safely (handle incompatible browsers)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages