mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-08-15 23:50:19 +02:00
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:
+17
-1
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -106,14 +106,14 @@ func TestWrite_CSV_Cookie(t *testing.T) {
|
||||
assert.Equal(t,
|
||||
[]string{
|
||||
"browser", "profile", "host", "path", "name", "value",
|
||||
"is_secure", "is_http_only", "has_expire", "is_persistent", "expire_at", "created_at",
|
||||
"is_secure", "is_http_only", "has_expire", "is_persistent", "expire_at", "created_at", "same_site",
|
||||
},
|
||||
records[0],
|
||||
)
|
||||
assert.Equal(t,
|
||||
[]string{
|
||||
"Chrome", "Default", ".example.com", "/", "session", "abc123",
|
||||
"true", "true", "true", "true", "2026-01-15T10:30:00Z", "2026-01-15T10:30:00Z",
|
||||
"true", "true", "true", "true", "2026-01-15T10:30:00Z", "2026-01-15T10:30:00Z", "",
|
||||
},
|
||||
records[1],
|
||||
)
|
||||
|
||||
@@ -54,7 +54,7 @@ func TestStructCSVHeader(t *testing.T) {
|
||||
expect []string
|
||||
}{
|
||||
{"LoginEntry", types.LoginEntry{}, []string{"url", "username", "password", "created_at"}},
|
||||
{"CookieEntry", types.CookieEntry{}, []string{"host", "path", "name", "value", "is_secure", "is_http_only", "has_expire", "is_persistent", "expire_at", "created_at"}},
|
||||
{"CookieEntry", types.CookieEntry{}, []string{"host", "path", "name", "value", "is_secure", "is_http_only", "has_expire", "is_persistent", "expire_at", "created_at", "same_site"}},
|
||||
{"BookmarkEntry", types.BookmarkEntry{}, []string{"id", "name", "type", "url", "folder", "created_at"}},
|
||||
{"HistoryEntry", types.HistoryEntry{}, []string{"url", "title", "visit_count", "last_visit"}},
|
||||
{"DownloadEntry", types.DownloadEntry{}, []string{"url", "target_path", "mime_type", "total_bytes", "start_time", "end_time"}},
|
||||
@@ -87,7 +87,7 @@ func TestStructCSVRow(t *testing.T) {
|
||||
IsSecure: true, IsHTTPOnly: true, HasExpire: true, IsPersistent: false,
|
||||
ExpireAt: refTime, CreatedAt: refTime,
|
||||
},
|
||||
[]string{".example.com", "/", "session", "abc", "true", "true", "true", "false", "2026-01-15T10:30:00Z", "2026-01-15T10:30:00Z"},
|
||||
[]string{".example.com", "/", "session", "abc", "true", "true", "true", "false", "2026-01-15T10:30:00Z", "2026-01-15T10:30:00Z", ""},
|
||||
},
|
||||
{
|
||||
"HistoryEntry_int",
|
||||
|
||||
Reference in New Issue
Block a user