Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vojtechvitek/samesite
Go pkg to set SameSite=None cookie attribute safely (handle incompatible browsers)
https://github.com/vojtechvitek/samesite
Last synced: about 2 months ago
JSON representation
Go pkg to set SameSite=None cookie attribute safely (handle incompatible browsers)
- Host: GitHub
- URL: https://github.com/vojtechvitek/samesite
- Owner: VojtechVitek
- License: mit
- Created: 2020-01-02T14:24:09.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-03T15:45:08.000Z (about 5 years ago)
- Last Synced: 2024-10-14T09:26:08.418Z (3 months ago)
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 3
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Set SameSite=None cookie attribute safely in Golang
[![GoDoc](https://godoc.org/github.com/VojtechVitek/samesite?status.svg)](https://godoc.org/github.com/VojtechVitek/samesite)
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:
```go
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)
}
```