Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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)

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)
}
```