Skip to content

fix(saz): accept U+FFFD in well-formed metadata - #2863

Closed
Dragolone wants to merge 7 commits into
morluto:mainfrom
Dragolone:fix/saz-metadata-replacement-character
Closed

Dragolone wants to merge 7 commits into
morluto:mainfrom
Dragolone:fix/saz-metadata-replacement-character

Conversation

@Dragolone

Copy link
Copy Markdown
Contributor

Summary

A SAZ capture is rejected as invalid input when any raw/N_m.xml metadata member contains U+FFFD (REPLACEMENT CHARACTER), even though the XML is well-formed.

xmldom 0.9.12 emits a warning ("Unicode replacement character detected, source encoding issues?") whenever the source text contains U+FFFD (lib/sax.js, start of parse). decodeSazMetadata treats every onError report, warnings included, as a well-formedness failure. U+FFFD is a legal XML Char ([#xE000-#xFFFD]). The decoder already uses a fatal TextDecoder, so a U+FFFD that reaches the parser was encoded in the source. It cannot be a decoding artifact, which is the case the warning is about.

Related: #2601 asks for the opposite direction in the same handler, rejecting &, NUL and surrogate references that are currently accepted. This PR does not change that behavior and does not conflict with it; it only stops rejecting one legal character. No issue covers this case: I searched for "SAZ metadata", "replacement character", "U+FFFD", "xmldom warning" and "Fiddler".

Problem and expected behavior

Smallest trigger: metadata <Session SID="1"><SessionFlags><SessionFlag N="ui-comments" V="caf�"/></SessionFlags></Session> (with a real U+FFFD) in an otherwise ordinary archive.

  • Before: rea inspect-web-network-capture fffd.saz saz --json reports {"category": "invalid_input", "code": "invalid_request"}, and decodeSazMetadata throws "SAZ metadata is not well-formed XML."
  • After: total_records: 1, with the attribute value retained as caf�.

Expected per docs/web-network-captures.md: malformed metadata fails validation; well-formed metadata is projected.

Change and scope

The onError handler ignores only the warning whose message starts with "Unicode replacement character detected". Every other warning, error or fatal error still sets parseFailed, so malformed XML is still rejected. That includes documents that also contain U+FFFD, and xmldom reports some of them only as warnings: unquoted attributes, attributes without separating whitespace, mismatched elements.

Not included: the stricter checks requested in #2601.

Contribution scope: an ordinary format-inspection correctness fix within existing boundaries; a maintainer scope decision is not applicable.

Contract and boundary impact

  • Semantic owner and earliest changed stage: decodeSazMetadata in src/browser/history/SazMetadata.ts.
  • Contribution scope fit and linked maintainer decision: in scope (format inspection); not applicable.
  • CLI and MCP/tool-catalog contract: no schema change; affected captures now succeed instead of failing as invalid input.
  • Provider, bridge, target-format, or platform compatibility: depends on xmldom's warning text; the dependency is pinned (0.9.12), and the new test fails if that message changes.
  • Evidence, artifact, provenance, or reconstruction contract: none; the character is retained verbatim.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: new src/browser/history/SazMetadata.test.ts:
    • "retains U+FFFD in well-formed metadata as an ordinary XML character" (an attribute and a text node);
    • "still rejects malformed metadata that also contains U+FFFD" for an unquoted attribute, attributes without separating whitespace, and a mismatched element.
  • Base reproduction: on 94072364c the first test fails with "SAZ metadata is not well-formed XML."; the rejection cases pass on both base and fix.
  • User-visible CLI output (rea inspect-web-network-capture fffd.saz saz --json): before {"category": "invalid_input", "code": "invalid_request"}, after normalized_result.total_records = 1.
  • Remaining proof gaps: I have not seen a Fiddler-produced SAZ with U+FFFD in metadata; the fixture is synthetic.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

macOS (Apple silicon), Node 24.19.0.

  • npx vitest run src/browser/history/SazMetadata.test.ts on the base — the retention test fails, the three rejection tests pass.
  • npx vitest run src/browser/history/ with the fix — 6 files, 103 tests passed.
  • npm run build:cached && npx vitest run tests/boundary/browser/sazWebCapture.test.ts — 13 passed, 1 skipped.
  • rea inspect-web-network-capture before/after as above.
  • npm run verify:test-discovery — "Discovered all 1089 test files exactly once."
  • npm run typecheck — passed.
  • npx oxfmt --check and npx oxlint on both changed files — passed, no errors.
  • npm run verify:module-boundaries — passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no change to DTD or entity handling; malformed XML stays rejected.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

xmldom warns whenever the source contains U+FFFD, and the metadata
decoder treated every parser report as a well-formedness failure, so a
capture whose metadata held a legal U+FFFD character was rejected as
invalid input. The fatal TextDecoder already rejects invalid source
bytes, so ignore only that warning; other warnings and errors still
reject the archive.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable defect was established.

Summary

decodeSazMetadata now ignores the replacement-character warning so well-formed metadata can retain U+FFFD.

  • SAZ metadata keeps U+FFFD when its XML is well-formed.

Reviews (5) · Last reviewed commit: "Merge branch 'main' into fix/saz-metadat..." · Reviewed by Greptile

dakjdakd and others added 6 commits October 14, 2026 00:57
* fix(comparison): preserve incomplete function call evidence

Keep missing, unknown, partial and unresolved call relationships unknown in function comparisons and reconstruction claims. Aggregate IDA caller and callee coverage without overwriting uncertainty.

Validate with 144 focused tests, typecheck/lint, docs checks and test discovery. Real providers were not verified; the full headless IDA session suite requires unavailable Windows native controls.

* fix(comparison): recheck historical calls-only changes

---------

Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
@morluto morluto added area: domain Domain logic, errors, and pure functions bug Something isn't working labels Oct 14, 2026
morluto added a commit that referenced this pull request Oct 14, 2026
Own service-worker CDP registrations and retry failed teardown. Admit redaction and network metadata against remaining capture capacity, retain explicit omission reasons, and preserve source URL, redirect ancestry, caller-selected content, and historical capture values. Forward CLI cancellation through provider cleanup.

Reviewed fixes: #2263, #2637, #2767, #2845, #2859, #2863, #2872, #2874, #2876, #2879, #2955, #2957, #2961, #3033.

Validation: 25 current event/network source tests passed; earlier focused browser lanes passed 201 source tests and 176 boundary tests with two skips, plus 35 Python tests. Real browser/Windows lanes were not rerun. Playwright allocation before admission remains unbounded by these retention limits.
@Dragolone

Copy link
Copy Markdown
Contributor Author

This change landed on main in f690571 (listed under "Reviewed fixes"), so I'm closing this PR. Thanks for reviewing it!

@Dragolone Dragolone closed this Oct 14, 2026
@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thanks @Dragolone for separating valid U+FFFD text from malformed SAZ XML. The current parser accepts well-formed metadata containing that character instead of treating the parser warning as a syntax failure (main).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants