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"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user