Skip to content

fix(browser)!: preserve storage value code units - #6341

Merged
morluto merged 1 commit into
morluto:mainfrom
gongfpp:fix/browser-storage-surrogates-6289
Oct 22, 2026
Merged

morluto merged 1 commit into
morluto:mainfrom
gongfpp:fix/browser-storage-surrogates-6289

Conversation

@gongfpp

@gongfpp gongfpp commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #6289. Preserve JavaScript storage value identity when strings contain unpaired UTF-16 surrogates; do not turn irreversible legacy information loss or encoding metadata into a website change.

Problem and expected behavior

On base 3d472bde23b70f9aa7bcf0d28a0cd10e469545e9, real owned Chromium plus public CLI capture/comparison returned unchanged for separately captured \ud800 and \ud801 local/session storage. Both values had SHA-256 83d544ccc223c057d2bf80d3f2a32982c32c3c0db8e2674820da5064783fb097: UTF-8 replaced the distinct code units before hashing.

New captures report these pairs, and \ud800 versus \ufffd, as changed. Independently recaptured identical values remain unchanged.

Change and scope

  • Fix the existing BrowserScenarioSecrets.fingerprint owner: ordinary strings keep their existing UTF-8 digest; unpaired code units use raw 0xff followed by exact UTF-16LE. The byte domains are disjoint. Declared secrets still return redacted-secret / null before hashing; no extra secret or legacy digest.
  • Successful storage snapshots carry optional-contract fingerprint_version: 2. Absence means legacy, not v2. The comparison boundary checks provenance before normalization and excludes the version from content projection.
  • Any legacy hashed storage conservatively yields unknown, even old-to-old and when a difference could otherwise be proven. This intentionally trades legacy comparison coverage for soundness; recapture both sides. Empty/all-secret-redacted storage retains its existing semantics. No legacy Evidence is rewritten. This compatibility policy remains subject to maintainer review.
  • Ordinary fix within existing active-scenario boundaries: maintainer execution-scope decision not applicable. No new provider, target authority, passive capture behavior, secret inference or storage ordering fix (fix(browser): ignore scenario storage enumeration order #5035 is separate).

Contract and boundary impact

  • Semantic owner: storage value fingerprint producer; active-scenario storage comparison owns comparability.
  • CLI/MCP: same operations and arguments; additive optional result field and corresponding generated catalog schema; legacy inputs remain accepted with explicit uncertainty.
  • Evidence: preserve capture identity, provenance, completeness and declared-secret redaction; retained MCP records remain available intact.
  • Existing active capture launches the caller-selected browser, seeds selected storage and evaluates its capture scripts. The regression exercises only an owned loopback fixture; no new runtime authority or external service.
  • No dependency, installation, package version or committed generated-output changes.

Evidence and regression coverage

Producer cases cover ordinary UTF-8, paired/unpaired units, an exact v2 byte golden, declared-secret redaction and a cross-encoding alias that defeats bare UTF-16LE fallback. Comparison cases cover all three storage collections, both legacy sides, different legacy digests, normalization order, and metadata-only changes.

The real-browser helper runs four independent captures through each public adapter (8 total), checks changed/unchanged controls, ordinary cookie/local/session digests, secret redaction, version-less imported results as unknown, CLI/MCP parity, full retained MCP records, server liveness and owned-profile cleanup. It is wired into the existing real-browser verifier.

Validation performed

On macOS arm64, pinned Node 24.18.0 / npm 11.16.0; base 2127095e3b4a377abbc124ca83af46b98a2a557b, tested head 8d46743eb64167eba7a0062a754d18ffb9316e8e:

  • npm run test:focused -- src/browser/BrowserScenario.test.ts src/browser/PlaywrightScenarioEvents.test.ts src/browser/PlaywrightScenarioArtifacts.test.ts src/browser/PlaywrightScenarioStorage.test.ts src/domain/browserScenarioCapture.test.ts src/domain/browserScenarioDiff.test.ts tests/boundary/mcp/browserScenarioMcp.test.ts — 86 tests passed.
  • Targeted verifyScenarioStorageFingerprints with the existing owned loopback verifier fixture and installed Chromium 155.0.8059.85 — passed: 8 independent captures, both adapters, imported version-less comparisons, retention and cleanup; 49.421 s including loopback-site setup/teardown (not a before/after performance benchmark).
  • npm run check:fast — typecheck/lint passed.
  • npm run docs:check — generated facts/catalog checks and 9 conformance tests passed.
  • npm run verify:test-discovery — all 2051 test files discovered exactly once.
  • git diff --check — passed. Independent read-only review found no blocking issue; its suggested codec/legacy regressions are included.

Compatibility, safety, and release

Breaking comparison behavior: previously accepted legacy captures still parse, but hashed legacy storage comparisons now return unknown; recapture both sides for sound value comparison. Already lost code units cannot be reconstructed. New ordinary-string digests remain compatible, without inferring that an unversioned capture was lossless.

Not run: the complete real-browser verifier, full test/CI suite, Windows/Linux, attached/passive-browser workflows or other providers. No performance claim; token usage, CPU and peak process-family memory were not measured. Local validation does not establish CI success, maintainer approval or merge permission.

Author readiness

Human owner: @gongfpp

AI-assisted contribution; the human owner confirmed review and requested initial maintainer review.

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • Human ownership/readiness and required current-head CI checks are complete.
  • Maintainer review confirms the conservative legacy comparison policy and contribution scope.

Keep ordinary UTF-8 digests and secret redaction, separate malformed UTF-16 preimages, and record storage fingerprint provenance. Compare legacy hashed snapshots as unknown without treating encoding metadata as a target change. Cover producer boundaries and real owned-browser CLI/MCP workflows.

BREAKING CHANGE: legacy hashed browser storage remains readable but comparisons return unknown until both sides are recaptured.
@gongfpp
gongfpp marked this pull request as ready for review October 22, 2026 17:22
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T17:29:25.120132Z 8d46743 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge, with no actionable issue found.

Summary

Preserves storage value code units when strings contain unpaired UTF-16 surrogates.

  • Storage captures preserve unpaired UTF-16 code units in their fingerprints.
  • Comparisons mark legacy hashed storage as unknown instead of trusting its digest.

Acknowledgment: gongfpp explicitly chose unknown for every comparison containing legacy hashed storage, including differing hashes. The stated reason is to avoid claiming certainty after irreversible information loss.

Review limits: Tests and the browser verifier were not run during this review. Whether this PR has been superseded could not be checked because GitHub access required authentication.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Storage value] --> B{Contains a declared secret?}
  B -->|Yes| C[Redacted; no hash]
  B -->|No| D{Contains an unpaired surrogate?}
  D -->|No| E[Hash UTF-8 bytes]
  D -->|Yes| F[Hash FF prefix and UTF-16LE bytes]
  E --> G[Snapshot version 2]
  F --> G
  H[Compare storage snapshots] --> I{Either side has legacy hashed values?}
  I -->|Yes| J[Unknown; recapture both sides]
  I -->|No| K[Compare content without version metadata]
Loading

Reviews (1) · Last reviewed commit: "fix(browser)!: preserve storage value co..." · Reviewed by Greptile

@morluto
morluto merged commit 7aee876 into morluto:main Oct 22, 2026
43 of 44 checks passed
@morluto morluto added the bug Something isn't working label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Distinct localStorage code units receive the same digest and scenarios compare unchanged

2 participants