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
+17 -1
View File
@@ -3,6 +3,7 @@ package output
import (
"encoding/json"
"io"
"strings"
"github.com/moond4rk/hackbrowserdata/types"
)
@@ -15,6 +16,8 @@ type cookieEditorFormatter struct {
func (f *cookieEditorFormatter) ext() string { return "json" }
var sameSiteNone = "no_restriction"
func (f *cookieEditorFormatter) format(w io.Writer, rows []row) error {
if len(rows) == 0 {
return nil
@@ -32,6 +35,13 @@ func (f *cookieEditorFormatter) format(w io.Writer, rows []row) error {
if !c.ExpireAt.IsZero() {
expDate = float64(c.ExpireAt.Unix())
}
sameSite := &c.SameSite
switch c.SameSite {
case "none":
sameSite = &sameSiteNone
case "", "unspecified":
sameSite = nil
}
entries = append(entries, cookieEditorEntry{
Domain: c.Host,
ExpirationDate: expDate,
@@ -40,6 +50,9 @@ func (f *cookieEditorFormatter) format(w io.Writer, rows []row) error {
Path: c.Path,
Secure: c.IsSecure,
Value: c.Value,
SameSite: sameSite,
Session: expDate == 0.,
HostOnly: !strings.HasPrefix(c.Host, "."),
})
}
@@ -52,10 +65,13 @@ func (f *cookieEditorFormatter) format(w io.Writer, rows []row) error {
// cookieEditorEntry matches the CookieEditor browser extension's import format.
type cookieEditorEntry struct {
Domain string `json:"domain"`
ExpirationDate float64 `json:"expirationDate"`
ExpirationDate float64 `json:"expirationDate,omitempty"`
HTTPOnly bool `json:"httpOnly"`
Name string `json:"name"`
Path string `json:"path"`
Secure bool `json:"secure"`
Value string `json:"value"`
SameSite *string `json:"sameSite"`
Session bool `json:"session"`
HostOnly bool `json:"hostOnly"`
}