feat: Add support for sameSite field (#628)

Recent browsers (and HTTP) added "sameSite" setting to limit cross site attacks.
Add support for exporting this property from Firefox and Chrome and to export to csv and cookie-editor format.
Also extract new "session" and "hostOnly" properties for cookie-editor format.
Tested on Firefox, Chrome and Chromium.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
This commit is contained in:
freddy77
2026-08-07 10:14:40 +08:00
committed by GitHub
parent df20f73b7a
commit 18d841f68f
6 changed files with 52 additions and 9 deletions
+15 -2
View File
@@ -14,7 +14,7 @@ import (
const (
defaultCookieQuery = `SELECT name, encrypted_value, host_key, path,
creation_utc, expires_utc, is_secure, is_httponly,
has_expires, is_persistent FROM cookies`
has_expires, is_persistent, samesite FROM cookies`
countCookieQuery = `SELECT COUNT(*) FROM cookies`
)
@@ -27,15 +27,27 @@ func extractCookies(masterKeys masterkey.MasterKeys, path string) ([]types.Cooki
hasExpire, isPersistent int
createdAt, expireAt int64
encryptedValue []byte
sameSite int
)
if err := rows.Scan(&name, &encryptedValue, &host, &cookiePath,
&createdAt, &expireAt, &isSecure, &isHTTPOnly,
&hasExpire, &isPersistent); err != nil {
&hasExpire, &isPersistent, &sameSite); err != nil {
return types.CookieEntry{}, err
}
value, _ := decryptValue(masterKeys, encryptedValue)
value = stripCookieHash(value, host)
sameSiteStr := "unspecified"
switch sameSite {
case 0:
sameSiteStr = "none"
case 1:
sameSiteStr = "lax"
case 2:
sameSiteStr = "strict"
case -1:
// not specified by Set-Cookie
}
return types.CookieEntry{
Name: name,
Host: host,
@@ -47,6 +59,7 @@ func extractCookies(masterKeys masterkey.MasterKeys, path string) ([]types.Cooki
IsPersistent: isPersistent != 0,
ExpireAt: timeEpoch(expireAt),
CreatedAt: timeEpoch(createdAt),
SameSite: sameSiteStr,
}, nil
})
if err != nil {