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:
@@ -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 {
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
const (
|
||||
firefoxCookieQuery = `SELECT name, value, host, path,
|
||||
creationTime, expiry, isSecure, isHttpOnly FROM moz_cookies`
|
||||
creationTime, expiry, isSecure, isHttpOnly, sameSite FROM moz_cookies`
|
||||
firefoxCountCookieQuery = `SELECT COUNT(*) FROM moz_cookies`
|
||||
)
|
||||
|
||||
@@ -21,12 +21,24 @@ func extractCookies(path string) ([]types.CookieEntry, error) {
|
||||
name, value, host, cookiePath string
|
||||
isSecure, isHTTPOnly int
|
||||
createdAt, expiry int64
|
||||
sameSite int
|
||||
)
|
||||
if err := rows.Scan(&name, &value, &host, &cookiePath,
|
||||
&createdAt, &expiry, &isSecure, &isHTTPOnly); err != nil {
|
||||
&createdAt, &expiry, &isSecure, &isHTTPOnly, &sameSite); err != nil {
|
||||
return types.CookieEntry{}, err
|
||||
}
|
||||
hasExpire := expiry > 0
|
||||
sameSiteStr := "unspecified"
|
||||
switch sameSite {
|
||||
case 0:
|
||||
sameSiteStr = "none"
|
||||
case 1:
|
||||
sameSiteStr = "lax"
|
||||
case 2:
|
||||
sameSiteStr = "strict"
|
||||
case 256:
|
||||
// not specified by Set-Cookie
|
||||
}
|
||||
return types.CookieEntry{
|
||||
Name: name,
|
||||
Host: host,
|
||||
@@ -38,6 +50,7 @@ func extractCookies(path string) ([]types.CookieEntry, error) {
|
||||
IsPersistent: hasExpire,
|
||||
ExpireAt: firefoxSeconds(expiry),
|
||||
CreatedAt: firefoxMicros(createdAt),
|
||||
SameSite: sameSiteStr,
|
||||
}, nil
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user