diff --git a/cmd/hack-browser-data/dump.go b/cmd/hack-browser-data/dump.go
index 03c5cda6..c0db00fb 100644
--- a/cmd/hack-browser-data/dump.go
+++ b/cmd/hack-browser-data/dump.go
@@ -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
}
diff --git a/cmd/hack-browser-data/restore.go b/cmd/hack-browser-data/restore.go
index 2f163422..84ac9abc 100644
--- a/cmd/hack-browser-data/restore.go
+++ b/cmd/hack-browser-data/restore.go
@@ -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")
diff --git a/cmd/hack-browser-data/testdata/flags.golden b/cmd/hack-browser-data/testdata/flags.golden
index 721f27f6..7a9d0216 100644
--- a/cmd/hack-browser-data/testdata/flags.golden
+++ b/cmd/hack-browser-data/testdata/flags.golden
@@ -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"
diff --git a/internal/app/collector.go b/internal/app/collector.go
index 1bc20d63..21ef5408 100644
--- a/internal/app/collector.go
+++ b/internal/app/collector.go
@@ -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 {
diff --git a/internal/app/dump.go b/internal/app/dump.go
index 9b97f0fa..5d497baa 100644
--- a/internal/app/dump.go
+++ b/internal/app/dump.go
@@ -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
}
diff --git a/internal/app/execute.go b/internal/app/execute.go
index b86d0dba..7082958f 100644
--- a/internal/app/execute.go
+++ b/internal/app/execute.go
@@ -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
diff --git a/internal/app/extract_golden_test.go b/internal/app/extract_golden_test.go
index 9b756211..d953c63e 100644
--- a/internal/app/extract_golden_test.go
+++ b/internal/app/extract_golden_test.go
@@ -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
diff --git a/internal/app/options.go b/internal/app/options.go
index dd4d9aa1..b9241747 100644
--- a/internal/app/options.go
+++ b/internal/app/options.go
@@ -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.
diff --git a/internal/app/restore.go b/internal/app/restore.go
index 6bdcb36c..9b9e2813 100644
--- a/internal/app/restore.go
+++ b/internal/app/restore.go
@@ -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
}
diff --git a/internal/app/restore_golden_test.go b/internal/app/restore_golden_test.go
index 4fed7063..1cd0339b 100644
--- a/internal/app/restore_golden_test.go
+++ b/internal/app/restore_golden_test.go
@@ -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)
diff --git a/internal/app/storage_limit_test.go b/internal/app/storage_limit_test.go
new file mode 100644
index 00000000..7796b81f
--- /dev/null
+++ b/internal/app/storage_limit_test.go
@@ -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))
+}
diff --git a/internal/app/testdata/extract-csv.golden b/internal/app/testdata/extract-csv.golden
index 1bf1d0b4..9b0cb51b 100644
--- a/internal/app/testdata/extract-csv.golden
+++ b/internal/app/testdata/extract-csv.golden
@@ -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"" & bold",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
diff --git a/internal/app/testdata/extract-json.golden b/internal/app/testdata/extract-json.golden
index 82ec72b5..9268e61e 100644
--- a/internal/app/testdata/extract-json.golden
+++ b/internal/app/testdata/extract-json.golden
@@ -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",
diff --git a/internal/app/testdata/extract-safari-csv.golden b/internal/app/testdata/extract-safari-csv.golden
index 7cc73281..ea3bda87 100644
--- a/internal/app/testdata/extract-safari-csv.golden
+++ b/internal/app/testdata/extract-safari-csv.golden
@@ -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
diff --git a/internal/app/testdata/extract-safari-json.golden b/internal/app/testdata/extract-safari-json.golden
index 513edbab..635b5561 100644
--- a/internal/app/testdata/extract-safari-json.golden
+++ b/internal/app/testdata/extract-safari-json.golden
@@ -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",
diff --git a/internal/app/testdata/restore-zip.golden b/internal/app/testdata/restore-zip.golden
index 99f39704..b84d2d5c 100644
--- a/internal/app/testdata/restore-zip.golden
+++ b/internal/app/testdata/restore-zip.golden
@@ -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
diff --git a/internal/browser/chromium/extract_storage.go b/internal/browser/chromium/extract_storage.go
index 842cf2ed..11b95480 100644
--- a/internal/browser/chromium/extract_storage.go
+++ b/internal/browser/chromium/extract_storage.go
@@ -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)
diff --git a/internal/browser/safari/extract_storage.go b/internal/browser/safari/extract_storage.go
index 0cbc1c16..e281a9b8 100644
--- a/internal/browser/safari/extract_storage.go
+++ b/internal/browser/safari/extract_storage.go
@@ -22,8 +22,6 @@ const (
webkitLocalStorageSubdir = "LocalStorage"
webkitLocalStorageDB = "localstorage.sqlite3"
webkitOriginSaltName = "salt" // HMAC salt sibling of the 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 {
diff --git a/internal/browser/safari/extract_storage_test.go b/internal/browser/safari/extract_storage_test.go
index 04307487..cf1bf8d8 100644
--- a/internal/browser/safari/extract_storage_test.go
+++ b/internal/browser/safari/extract_storage_test.go
@@ -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) {