mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
feat(storage): add --max-storage-value flag (#703)
Each browser capped storage values at its own byte limit, or not at all; one flag now caps decoded characters for every browser (default 2048, 0 = unlimited).
This commit is contained in:
1 parent
43d9d31130
commit
c733ac9d6d
19 files changed
+141
-76
No files matched your search
@@ -36,6 +36,7 @@ func newDumpCommand() *cobra.Command {
|
||||
command.Flags().StringVarP(&flags.ProfilePath, "profile-path", "p", "", "custom profile dir path, get with chrome://version")
|
||||
addKeychainPasswordFlags(command, &keychain)
|
||||
command.Flags().BoolVar(&flags.Zip, "zip", false, "compress output to zip")
|
||||
command.Flags().IntVar(&flags.MaxStorageValue, "max-storage-value", app.DefaultMaxStorageValue, "max storage value chars, 0=unlimited")
|
||||
|
||||
return command
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ func newRestoreCommand() *cobra.Command {
|
||||
command.Flags().StringVarP(&flags.Format, "format", "f", "json", "output format: csv|json|cookie-editor")
|
||||
command.Flags().StringVarP(&flags.OutputDir, "dir", "d", "results", "output directory")
|
||||
command.Flags().BoolVar(&flags.Zip, "zip", false, "compress output to zip")
|
||||
command.Flags().IntVar(&flags.MaxStorageValue, "max-storage-value", app.DefaultMaxStorageValue, "max storage value chars, 0=unlimited")
|
||||
|
||||
_ = command.MarkFlagRequired("keys")
|
||||
command.MarkFlagsMutuallyExclusive("data-dir", "data-zip")
|
||||
|
||||
+3
@@ -5,6 +5,7 @@ hack-browser-data --format -f string "json"
|
||||
hack-browser-data --help -h bool "false"
|
||||
hack-browser-data --keychain-pw string ""
|
||||
hack-browser-data --keychain-pw-stdin bool "false"
|
||||
hack-browser-data --max-storage-value int "2048"
|
||||
hack-browser-data --profile-path -p string ""
|
||||
hack-browser-data --verbose -v bool "false" persistent
|
||||
hack-browser-data --zip bool "false"
|
||||
@@ -20,6 +21,7 @@ hack-browser-data dump --format -f string "json"
|
||||
hack-browser-data dump --help -h bool "false"
|
||||
hack-browser-data dump --keychain-pw string ""
|
||||
hack-browser-data dump --keychain-pw-stdin bool "false"
|
||||
hack-browser-data dump --max-storage-value int "2048"
|
||||
hack-browser-data dump --profile-path -p string ""
|
||||
hack-browser-data dump --zip bool "false"
|
||||
hack-browser-data dump --verbose -v bool "false" inherited
|
||||
@@ -40,6 +42,7 @@ hack-browser-data restore --dir -d string "results"
|
||||
hack-browser-data restore --format -f string "json"
|
||||
hack-browser-data restore --help -h bool "false"
|
||||
hack-browser-data restore --keys string ""
|
||||
hack-browser-data restore --max-storage-value int "2048"
|
||||
hack-browser-data restore --zip bool "false"
|
||||
hack-browser-data restore --verbose -v bool "false" inherited
|
||||
hack-browser-data version --help -h bool "false"
|
||||
|
||||
@@ -2,7 +2,9 @@ package app
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
@@ -13,13 +15,39 @@ type collector struct {
|
||||
records []record.Record
|
||||
failures int
|
||||
firstFailure error
|
||||
maxStorageValue int
|
||||
}
|
||||
|
||||
func (c *collector) Add(row record.Record) {
|
||||
row.SetBrowserAndProfile(c.browserName, c.profileName)
|
||||
capStorageValue(row, c.maxStorageValue)
|
||||
c.records = append(c.records, row)
|
||||
}
|
||||
|
||||
// capStorageValue replaces an over-long localStorage/sessionStorage value with a size marker; limit <= 0 keeps it whole.
|
||||
func capStorageValue(row record.Record, limit int) {
|
||||
if limit <= 0 {
|
||||
return
|
||||
}
|
||||
switch stored := row.(type) {
|
||||
case *record.LocalStorage:
|
||||
if !stored.IsMeta {
|
||||
stored.Value = cappedValue(stored.Value, limit)
|
||||
}
|
||||
case *record.SessionStorage:
|
||||
if !stored.IsMeta {
|
||||
stored.Value = cappedValue(stored.Value, limit)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func cappedValue(value string, limit int) string {
|
||||
if count := utf8.RuneCountInString(value); count > limit {
|
||||
return fmt.Sprintf("value too long: %d chars (max %d, raise with --max-storage-value)", count, limit)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func (c *collector) Fail(err error) {
|
||||
c.failures++
|
||||
if c.firstFailure == nil {
|
||||
|
||||
+11
-7
@@ -13,12 +13,13 @@ import (
|
||||
|
||||
// DumpFlags are dump's command-line values as cobra parsed them.
|
||||
type DumpFlags struct {
|
||||
Browser string
|
||||
Categories string
|
||||
Format string
|
||||
OutputDir string
|
||||
Zip bool
|
||||
ProfilePath string
|
||||
Browser string
|
||||
Categories string
|
||||
Format string
|
||||
OutputDir string
|
||||
Zip bool
|
||||
ProfilePath string
|
||||
MaxStorageValue int
|
||||
}
|
||||
|
||||
type DumpOptions struct {
|
||||
@@ -49,6 +50,9 @@ func ValidateDump(flags DumpFlags, keychainPassword func(context.Context) (strin
|
||||
if err != nil {
|
||||
return DumpOptions{}, err
|
||||
}
|
||||
if err := checkMaxStorageValue(flags.MaxStorageValue); err != nil {
|
||||
return DumpOptions{}, err
|
||||
}
|
||||
home, err := homeDir()
|
||||
if err != nil {
|
||||
return DumpOptions{}, err
|
||||
@@ -56,7 +60,7 @@ func ValidateDump(flags DumpFlags, keychainPassword func(context.Context) (strin
|
||||
return DumpOptions{
|
||||
Target: Target{Browsers: browsers, ProfilePath: profilePath, HomeDir: home},
|
||||
Categories: categories,
|
||||
Output: Output{Dir: flags.OutputDir, Format: format, Zip: flags.Zip},
|
||||
Output: Output{Dir: flags.OutputDir, Format: format, Zip: flags.Zip, MaxStorageValue: flags.MaxStorageValue},
|
||||
Keychain: KeychainConfig{Path: loginKeychainPath(home), Password: keychainPassword},
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ func execute(ctx context.Context, discovery Discovery, categories []category.Cat
|
||||
return Summary{}, err
|
||||
}
|
||||
dirRunner.writer, dirRunner.logProgress = writer, true
|
||||
dirRunner.maxStorageValue = output.MaxStorageValue
|
||||
summary, err := dirRunner.run(ctx, discovery, categories)
|
||||
closeErr := writer.Close()
|
||||
summary.Exported = writer.Listing()
|
||||
@@ -51,11 +52,12 @@ type recordWriter interface {
|
||||
|
||||
// runner is what every user data dir of one run shares; logProgress logs each dir as it starts.
|
||||
type runner struct {
|
||||
writer recordWriter
|
||||
extractors extractorsFunc
|
||||
retrieveKeys dirKeysFunc
|
||||
loginKeychain browser.LoginKeychain
|
||||
logProgress bool
|
||||
writer recordWriter
|
||||
extractors extractorsFunc
|
||||
retrieveKeys dirKeysFunc
|
||||
loginKeychain browser.LoginKeychain
|
||||
logProgress bool
|
||||
maxStorageValue int
|
||||
}
|
||||
|
||||
func (r runner) run(ctx context.Context, discovery Discovery, categories []category.Category) (Summary, error) {
|
||||
@@ -125,7 +127,7 @@ func (r runner) runDir(ctx context.Context, dir browser.UserDataDir, categories
|
||||
func (r runner) runExtraction(
|
||||
ctx context.Context, extraction plannedExtraction, input browser.Input, browserName string,
|
||||
) (Result, error) {
|
||||
recordCollector := &collector{browserName: browserName, profileName: extraction.ProfileName}
|
||||
recordCollector := &collector{browserName: browserName, profileName: extraction.ProfileName, maxStorageValue: r.maxStorageValue}
|
||||
err := extraction.extractor.Extract(ctx, input, recordCollector)
|
||||
if writeErr := r.writer.Write(extraction.Category, recordCollector.records); writeErr != nil {
|
||||
return Result{}, writeErr
|
||||
|
||||
@@ -59,7 +59,7 @@ func TestExtractGoldenSafari(t *testing.T) {
|
||||
func extractGoldenRun(t *testing.T, home string, keys map[browser.UserDataDirID]masterkey.Set, format string) string {
|
||||
t.Helper()
|
||||
out := t.TempDir()
|
||||
options, err := app.ValidateDump(app.DumpFlags{Browser: "all", Categories: "all", Format: format, OutputDir: out}, nil)
|
||||
options, err := app.ValidateDump(app.DumpFlags{Browser: "all", Categories: "all", Format: format, OutputDir: out, MaxStorageValue: app.DefaultMaxStorageValue}, nil)
|
||||
require.NoError(t, err)
|
||||
options.Target.HomeDir = home
|
||||
|
||||
|
||||
+14
-3
@@ -23,9 +23,20 @@ type Target struct {
|
||||
|
||||
// Output is where and how Execute writes records.
|
||||
type Output struct {
|
||||
Dir string
|
||||
Format export.Format
|
||||
Zip bool
|
||||
Dir string
|
||||
Format export.Format
|
||||
Zip bool
|
||||
MaxStorageValue int // localStorage/sessionStorage value characters kept before a size marker replaces it; <= 0 keeps all
|
||||
}
|
||||
|
||||
// DefaultMaxStorageValue bounds a stored value's characters unless --max-storage-value overrides it; 0 disables the bound.
|
||||
const DefaultMaxStorageValue = 2048
|
||||
|
||||
func checkMaxStorageValue(value int) error {
|
||||
if value < 0 {
|
||||
return fmt.Errorf("--max-storage-value must be >= 0 (0 means unlimited), got %d", value)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// KeychainConfig locates the macOS login keychain and says how to get its password; other systems ignore it.
|
||||
|
||||
+13
-9
@@ -18,14 +18,15 @@ import (
|
||||
|
||||
// RestoreFlags are restore's command-line values as cobra parsed them.
|
||||
type RestoreFlags struct {
|
||||
KeyFile string // a keys.json path, or "-" for stdin
|
||||
DataDir string
|
||||
DataZip string
|
||||
Browser string
|
||||
Categories string
|
||||
Format string
|
||||
OutputDir string
|
||||
Zip bool
|
||||
KeyFile string // a keys.json path, or "-" for stdin
|
||||
DataDir string
|
||||
DataZip string
|
||||
Browser string
|
||||
Categories string
|
||||
Format string
|
||||
OutputDir string
|
||||
Zip bool
|
||||
MaxStorageValue int
|
||||
}
|
||||
|
||||
type RestoreOptions struct {
|
||||
@@ -54,6 +55,9 @@ func ValidateRestore(flags RestoreFlags, stdin io.Reader) (RestoreOptions, error
|
||||
if err := checkOutputDir(flags.OutputDir); err != nil {
|
||||
return RestoreOptions{}, err
|
||||
}
|
||||
if err := checkMaxStorageValue(flags.MaxStorageValue); err != nil {
|
||||
return RestoreOptions{}, err
|
||||
}
|
||||
if err := checkRestoreData(flags.DataDir, flags.DataZip); err != nil {
|
||||
return RestoreOptions{}, err
|
||||
}
|
||||
@@ -68,7 +72,7 @@ func ValidateRestore(flags RestoreFlags, stdin io.Reader) (RestoreOptions, error
|
||||
return RestoreOptions{
|
||||
Vaults: vaults,
|
||||
Categories: categories,
|
||||
Output: Output{Dir: flags.OutputDir, Format: format, Zip: flags.Zip},
|
||||
Output: Output{Dir: flags.OutputDir, Format: format, Zip: flags.Zip, MaxStorageValue: flags.MaxStorageValue},
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -115,6 +115,7 @@ func restoreGolden(t *testing.T, flags app.RestoreFlags) string {
|
||||
if flags.Format == "" {
|
||||
flags.Format = "json"
|
||||
}
|
||||
flags.MaxStorageValue = app.DefaultMaxStorageValue // match the extract goldens, which cap at the default
|
||||
options, err := app.ValidateRestore(flags, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
)
|
||||
|
||||
func TestCapStorageValue(t *testing.T) {
|
||||
short := &record.LocalStorage{Value: strings.Repeat("x", 10)}
|
||||
meta := &record.LocalStorage{Value: strings.Repeat("y", 100), IsMeta: true}
|
||||
session := &record.SessionStorage{Value: strings.Repeat("z", 100)}
|
||||
cookie := &record.Cookie{Value: strings.Repeat("c", 100)}
|
||||
for _, row := range []record.Record{short, meta, session, cookie} {
|
||||
capStorageValue(row, 50)
|
||||
}
|
||||
|
||||
assert.Equal(t, strings.Repeat("x", 10), short.Value, "under limit is kept")
|
||||
assert.Equal(t, strings.Repeat("y", 100), meta.Value, "meta is never capped")
|
||||
assert.Contains(t, session.Value, "value too long", "over limit is marked")
|
||||
assert.Equal(t, strings.Repeat("c", 100), cookie.Value, "non-storage is untouched")
|
||||
}
|
||||
|
||||
func TestCapStorageValue_BoundaryAndUnlimited(t *testing.T) {
|
||||
exact := &record.LocalStorage{Value: strings.Repeat("x", 50)}
|
||||
capStorageValue(exact, 50)
|
||||
assert.Equal(t, strings.Repeat("x", 50), exact.Value, "a value of exactly the limit is kept")
|
||||
|
||||
unlimited := &record.LocalStorage{Value: strings.Repeat("x", 5000)}
|
||||
capStorageValue(unlimited, 0)
|
||||
assert.Len(t, unlimited.Value, 5000, "limit <= 0 keeps every value")
|
||||
}
|
||||
|
||||
func TestCappedValue_CountsRunesNotBytes(t *testing.T) {
|
||||
// 40 CJK runes decode fine but span 120 UTF-8 bytes; the limit is runes, so this stays under a 50 limit.
|
||||
value := strings.Repeat("世", 40)
|
||||
assert.Equal(t, value, cappedValue(value, 50))
|
||||
}
|
||||
+5
-5
@@ -78,27 +78,27 @@ Microsoft Edge,Default,https://news.home.edge.test/ja,ニュース,3,2024-03-01T
|
||||
Microsoft Edge,Profile 1,https://www.work.edge.test/,Home,42,2024-06-01T12:00:00Z
|
||||
Microsoft Edge,Profile 1,https://docs.work.edge.test/guide?q=go&lang=en,"Guide, ""quoted"" & <b>bold</b>",7,2024-06-01T13:00:00Z
|
||||
Microsoft Edge,Profile 1,https://news.work.edge.test/ja,ニュース,3,2024-06-01T14:00:00Z
|
||||
-- localstorage.csv (1829 bytes) --
|
||||
-- localstorage.csv (1853 bytes) --
|
||||
browser,profile,is_meta,url,key,value
|
||||
Chrome,Default,true,https://app.home.chrome.test,,"meta data, value bytes is [8 150 1]"
|
||||
Chrome,Default,true,https://app.home.chrome.test,,"meta data, value bytes is [16 32]"
|
||||
Chrome,Default,false,https://app.home.chrome.test,言語,日本語
|
||||
Chrome,Default,false,https://app.home.chrome.test,blob,"value is too long, length is 2101, supported max length is 2048"
|
||||
Chrome,Default,false,https://app.home.chrome.test,blob,"value too long: 2100 chars (max 2048, raise with --max-storage-value)"
|
||||
Chrome,Default,false,https://app.home.chrome.test,greeting,café
|
||||
Chrome,Profile 1,true,https://app.work.chrome.test,,"meta data, value bytes is [8 150 1]"
|
||||
Chrome,Profile 1,true,https://app.work.chrome.test,,"meta data, value bytes is [16 32]"
|
||||
Chrome,Profile 1,false,https://app.work.chrome.test,言語,日本語
|
||||
Chrome,Profile 1,false,https://app.work.chrome.test,blob,"value is too long, length is 2101, supported max length is 2048"
|
||||
Chrome,Profile 1,false,https://app.work.chrome.test,blob,"value too long: 2100 chars (max 2048, raise with --max-storage-value)"
|
||||
Chrome,Profile 1,false,https://app.work.chrome.test,greeting,café
|
||||
Microsoft Edge,Default,true,https://app.home.edge.test,,"meta data, value bytes is [8 150 1]"
|
||||
Microsoft Edge,Default,true,https://app.home.edge.test,,"meta data, value bytes is [16 32]"
|
||||
Microsoft Edge,Default,false,https://app.home.edge.test,言語,日本語
|
||||
Microsoft Edge,Default,false,https://app.home.edge.test,blob,"value is too long, length is 2101, supported max length is 2048"
|
||||
Microsoft Edge,Default,false,https://app.home.edge.test,blob,"value too long: 2100 chars (max 2048, raise with --max-storage-value)"
|
||||
Microsoft Edge,Default,false,https://app.home.edge.test,greeting,café
|
||||
Microsoft Edge,Profile 1,true,https://app.work.edge.test,,"meta data, value bytes is [8 150 1]"
|
||||
Microsoft Edge,Profile 1,true,https://app.work.edge.test,,"meta data, value bytes is [16 32]"
|
||||
Microsoft Edge,Profile 1,false,https://app.work.edge.test,言語,日本語
|
||||
Microsoft Edge,Profile 1,false,https://app.work.edge.test,blob,"value is too long, length is 2101, supported max length is 2048"
|
||||
Microsoft Edge,Profile 1,false,https://app.work.edge.test,blob,"value too long: 2100 chars (max 2048, raise with --max-storage-value)"
|
||||
Microsoft Edge,Profile 1,false,https://app.work.edge.test,greeting,café
|
||||
-- password.csv (1170 bytes) --
|
||||
browser,profile,url,username,password,created_at,store
|
||||
|
||||
+5
-5
@@ -776,7 +776,7 @@
|
||||
"last_visit": "2024-06-01T14:00:00Z"
|
||||
}
|
||||
]
|
||||
-- localstorage.json (3847 bytes) --
|
||||
-- localstorage.json (3871 bytes) --
|
||||
[
|
||||
{
|
||||
"browser": "Chrome",
|
||||
@@ -808,7 +808,7 @@
|
||||
"is_meta": false,
|
||||
"url": "https://app.home.chrome.test",
|
||||
"key": "blob",
|
||||
"value": "value is too long, length is 2101, supported max length is 2048"
|
||||
"value": "value too long: 2100 chars (max 2048, raise with --max-storage-value)"
|
||||
},
|
||||
{
|
||||
"browser": "Chrome",
|
||||
@@ -848,7 +848,7 @@
|
||||
"is_meta": false,
|
||||
"url": "https://app.work.chrome.test",
|
||||
"key": "blob",
|
||||
"value": "value is too long, length is 2101, supported max length is 2048"
|
||||
"value": "value too long: 2100 chars (max 2048, raise with --max-storage-value)"
|
||||
},
|
||||
{
|
||||
"browser": "Chrome",
|
||||
@@ -888,7 +888,7 @@
|
||||
"is_meta": false,
|
||||
"url": "https://app.home.edge.test",
|
||||
"key": "blob",
|
||||
"value": "value is too long, length is 2101, supported max length is 2048"
|
||||
"value": "value too long: 2100 chars (max 2048, raise with --max-storage-value)"
|
||||
},
|
||||
{
|
||||
"browser": "Microsoft Edge",
|
||||
@@ -928,7 +928,7 @@
|
||||
"is_meta": false,
|
||||
"url": "https://app.work.edge.test",
|
||||
"key": "blob",
|
||||
"value": "value is too long, length is 2101, supported max length is 2048"
|
||||
"value": "value too long: 2100 chars (max 2048, raise with --max-storage-value)"
|
||||
},
|
||||
{
|
||||
"browser": "Microsoft Edge",
|
||||
|
||||
+2
-2
@@ -34,10 +34,10 @@ Safari,default,https://files.home.safari.test/report.pdf,,0,
|
||||
Safari,Work,https://intranet.work.safari.test/,Intranet,12,2024-03-01T15:00:00Z
|
||||
Safari,Work,https://wiki.work.safari.test/onboarding,Onboarding,2,2024-03-01T16:00:00Z
|
||||
Safari,profile-9a1b2c3d,https://www.untitled.safari.test/,Untitled,1,2024-03-01T17:00:00Z
|
||||
-- localstorage.csv (423 bytes) --
|
||||
-- localstorage.csv (1458 bytes) --
|
||||
browser,profile,is_meta,url,key,value
|
||||
Safari,default,false,https://cdn.home.safari.test:8443,consent,yes
|
||||
Safari,default,false,https://app.home.safari.test,blob,"value is too long, length is 2200, supported max length is 2048"
|
||||
Safari,default,false,https://app.home.safari.test,blob,xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
Safari,default,false,https://app.home.safari.test,greeting,café
|
||||
Safari,default,false,https://app.home.safari.test,言語,日本語
|
||||
Safari,Work,false,https://app.work.safari.test,greeting,hello
|
||||
+2
-2
@@ -289,7 +289,7 @@
|
||||
"last_visit": "2024-03-01T17:00:00Z"
|
||||
}
|
||||
]
|
||||
-- localstorage.json (903 bytes) --
|
||||
-- localstorage.json (1940 bytes) --
|
||||
[
|
||||
{
|
||||
"browser": "Safari",
|
||||
@@ -305,7 +305,7 @@
|
||||
"is_meta": false,
|
||||
"url": "https://app.home.safari.test",
|
||||
"key": "blob",
|
||||
"value": "value is too long, length is 2200, supported max length is 2048"
|
||||
"value": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
},
|
||||
{
|
||||
"browser": "Safari",
|
||||
|
||||
+1
-1
@@ -4,6 +4,6 @@ creditcard.json method=8 modified=1979-11-30T00:00:00Z size=2331 crc32=72f10626
|
||||
download.json method=8 modified=1979-11-30T00:00:00Z size=2619 crc32=f0f92d58
|
||||
extension.json method=8 modified=1979-11-30T00:00:00Z size=3171 crc32=7448348e
|
||||
history.json method=8 modified=1979-11-30T00:00:00Z size=2659 crc32=29a3b1e3
|
||||
localstorage.json method=8 modified=1979-11-30T00:00:00Z size=3847 crc32=91270862
|
||||
localstorage.json method=8 modified=1979-11-30T00:00:00Z size=3871 crc32=616b1b5b
|
||||
password.json method=8 modified=1979-11-30T00:00:00Z size=2437 crc32=8ffca925
|
||||
sessionstorage.json method=8 modified=1979-11-30T00:00:00Z size=2115 crc32=b5898fc7
|
||||
@@ -25,8 +25,6 @@ const (
|
||||
stringFormatLatin1 = 1
|
||||
)
|
||||
|
||||
const maxLocalStorageValueLength = 2048
|
||||
|
||||
// readOnly keeps the open from replaying the journal into new files in the copy, a write that can fail on Windows.
|
||||
var readOnly = &opt.Options{ReadOnly: true}
|
||||
|
||||
@@ -135,12 +133,6 @@ func decodeUTF16LE(encoded []byte) (string, error) {
|
||||
}
|
||||
|
||||
func decodeLocalStorageValue(value []byte) string {
|
||||
if len(value) >= maxLocalStorageValueLength {
|
||||
return fmt.Sprintf(
|
||||
"value is too long, length is %d, supported max length is %d",
|
||||
len(value), maxLocalStorageValueLength,
|
||||
)
|
||||
}
|
||||
decoded, err := decodeStorageString(value)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("unsupported value encoding: %v", err)
|
||||
|
||||
@@ -22,8 +22,6 @@ const (
|
||||
webkitLocalStorageSubdir = "LocalStorage"
|
||||
webkitLocalStorageDB = "localstorage.sqlite3"
|
||||
webkitOriginSaltName = "salt" // HMAC salt sibling of the <hash> dirs; not a data dir
|
||||
|
||||
maxLocalStorageValueLength = 2048
|
||||
)
|
||||
|
||||
// origin file encoding-byte constants (WebCore SecurityOrigin serialization).
|
||||
@@ -216,22 +214,11 @@ func extractOriginStorage(path, origin string, out browser.Collector) error {
|
||||
out.Fail(fmt.Errorf("row with NULL key in %s", path))
|
||||
continue
|
||||
}
|
||||
out.Add(&record.LocalStorage{URL: origin, Key: key.String, Value: decodeLocalStorageValue(value)})
|
||||
out.Add(&record.LocalStorage{URL: origin, Key: key.String, Value: decodeUTF16LE(value)})
|
||||
}
|
||||
return rows.Err()
|
||||
}
|
||||
|
||||
// decodeLocalStorageValue turns values at or above the cap into a size marker to bound the output, as Chromium's does.
|
||||
func decodeLocalStorageValue(encoded []byte) string {
|
||||
if len(encoded) >= maxLocalStorageValueLength {
|
||||
return fmt.Sprintf(
|
||||
"value is too long, length is %d, supported max length is %d",
|
||||
len(encoded), maxLocalStorageValueLength,
|
||||
)
|
||||
}
|
||||
return decodeUTF16LE(encoded)
|
||||
}
|
||||
|
||||
// decodeUTF16LE returns an odd-length value as is, so a stray byte does not drop the row.
|
||||
func decodeUTF16LE(encoded []byte) string {
|
||||
if len(encoded) == 0 {
|
||||
|
||||
@@ -109,17 +109,6 @@ func TestDecodeUTF16LE(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestDecodeLocalStorageValue_Truncates(t *testing.T) {
|
||||
// 1100 chars × 2 bytes = 2200 bytes, over the 2048 cap.
|
||||
oversized := encodeUTF16LE(strings.Repeat("x", 1100))
|
||||
got := decodeLocalStorageValue(oversized)
|
||||
assert.Contains(t, got, "too long")
|
||||
assert.Contains(t, got, "2048")
|
||||
|
||||
assert.Contains(t, decodeLocalStorageValue(encodeUTF16LE(strings.Repeat("x", 1024))), "length is 2048", "the cap itself is too long")
|
||||
assert.Equal(t, strings.Repeat("x", 1023), decodeLocalStorageValue(encodeUTF16LE(strings.Repeat("x", 1023))))
|
||||
}
|
||||
|
||||
func TestExtractLocalStorage_SingleOrigin(t *testing.T) {
|
||||
root := buildTestLocalStorageDir(t, map[string][]testLocalStorageItem{
|
||||
"https://example.com": {{Key: "auth_token", Value: "abc123"}},
|
||||
@@ -191,7 +180,8 @@ func TestExtractLocalStorage_EmptyItemTable(t *testing.T) {
|
||||
assert.Empty(t, entries)
|
||||
}
|
||||
|
||||
func TestExtractLocalStorage_TruncatesOversizedValue(t *testing.T) {
|
||||
func TestExtractLocalStorage_EmitsFullValue(t *testing.T) {
|
||||
// The size bound moved to the app layer, so the extractor now emits the whole value.
|
||||
root := buildTestLocalStorageDir(t, map[string][]testLocalStorageItem{
|
||||
"https://example.com": {{Key: "big", Value: strings.Repeat("x", 1100)}},
|
||||
})
|
||||
@@ -200,7 +190,7 @@ func TestExtractLocalStorage_TruncatesOversizedValue(t *testing.T) {
|
||||
entries := collected[record.LocalStorage](t, &out)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, entries, 1)
|
||||
assert.Contains(t, entries[0].Value, "too long")
|
||||
assert.Equal(t, strings.Repeat("x", 1100), entries[0].Value)
|
||||
}
|
||||
|
||||
func TestExtractLocalStorage_Partitioned(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user