[PR #4524] [MERGED] fix(browser): reject invalid UTF-8 in HTTP CDP discovery #6285

Closed
opened 2026-10-31 01:13:17 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/4524
Author: @Afloat16
Created: 10/16/2026
Status: ✅ Merged
Merged: 10/27/2026
Merged by: @morluto

Base: main ← Head: fix/cdp-discovery-utf8


📝 Commits (2)

  • f68ed38 fix(browser): reject invalid UTF-8 in HTTP CDP discovery
  • cd289ba Merge upstream main into fix/cdp-discovery-utf8

📊 Changes

2 files changed (+102 additions, -4 deletions)

View changed files

📝 src/browser/CdpEndpoint.ts (+12 -3)
📝 tests/boundary/browser/cdpEndpointResponseBounds.test.ts (+90 -1)

📄 Description

Summary

Reject malformed UTF-8 in HTTP CDP discovery responses before JSON decoding can replace source bytes.

Problem and expected behavior

HTTP CDP discovery currently decodes bytes with Buffer.toString("utf8") before parsing JSON. Malformed bytes inside a target title or URL become replacement characters and are accepted as different source values.

Malformed UTF-8 must be rejected rather than silently changing a target title or URL. Valid Unicode, including a literal replacement character, remains valid.

Change and scope

Validate the complete, already size-bounded response with node:buffer.isUtf8 before decoding. Reject malformed bytes using the existing invalid_endpoint_response error. Keep valid U+FFFD/multibyte strings and existing BOM/JSON handling unchanged. This affects HTTP discovery only; endpoint authorization, WebSocket framing, byte/time limits, cancellation and provider capabilities are unchanged.

This is an ordinary validation fix within the existing HTTP discovery boundary; a separate new-provider or target-execution scope decision is not applicable. It follows the contribution scope.

Related candidate inventory: https://github.com/morluto/rea/discussions/3847#discussioncomment-18942539. Current main and related open/closed issue/PR searches were checked before submission; no equivalent HTTP discovery UTF-8 fix was found.

Contract and boundary impact

  • Semantic owner and earliest changed stage: readCdpJson, after complete size-bounded byte collection and before UTF-8 decoding/JSON parsing.
  • Contribution scope fit and linked maintainer decision: ordinary fix to an existing supported workflow; no new provider or execution capability.
  • CLI and MCP/tool-catalog contract: existing list-browser-targets / list_browser_targets return the existing invalid_endpoint_response failure for malformed discovery bytes. No command, schema or catalog entry is added.
  • Provider, bridge, target-format, or platform compatibility: HTTP CDP discovery only; the validation uses the pinned Node runtime's node:buffer.isUtf8.
  • Evidence, artifact, provenance, or reconstruction contract: reject corrupted source values instead of retaining replacement-decoded titles/URLs; valid returned target values remain unchanged.
  • Target selection, authority, upstream behavior, and cleanup details: discovery contacts the caller-selected HTTP endpoint through the existing authorization and cleanup path; no new attachment, script execution or mutation is introduced.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: no authored contract/package/installation change and no generated outputs in this diff.

Expected effects describe the production discovery operation, including its existing HTTP requests. Test runners and CLI/MCP subprocesses are validation activities.

  • 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: malformed target-title/URL bytes, recovery on the next discovery, valid split multibyte text/literal U+FFFD and leading-BOM rejection in cdpEndpointResponseBounds.test.ts.
  • Base reproduction: the identical file fails twice on the recorded base and passes all nine tests with the fix, as detailed below.
  • User-visible CLI/MCP outcome: the recorded fresh compiled calls reject malformed title/URL and BOM inputs using the existing discovery error; valid split-Unicode input succeeds through both public adapters.
  • Remaining proof gaps: the loopback server is simulated; no local real-browser, attached-target, packaged-install or native-platform qualification is claimed. The results below belong to the recorded head/base, not today's main.

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

Base: main f4337864633ce3ac44bf4d0d888deeecb0722ea7. This branch retains the existing fix and synchronizes that main without unrelated authored edits.

  • Identical discovery regression file: 2 failures / 7 passes on main; 9 passes after. Covers damaged title/URL bytes, next-discovery recovery, split multibyte HTTP chunks, literal U+FFFD, BOM rejection and existing size/deadline/cancellation/status controls.
  • 38 related tests / 7 files pass, including discovery authorization, browser-socket routing, target inventory, protocol failures and shared workflow/domain controls.
  • Fresh compiled list-browser-targets CLI and real SDK stdio list_browser_targets each pass 4 loopback HTTP cases: malformed title, malformed URL, BOM, and valid split Unicode. Each public call is observed requesting both discovery endpoints. Four direct compiled discovery controls also pass.
  • Official compile:termux, TypeScript 6 checking, lint/module boundaries, knip, metadata, architecture/discovery, changed-file formatting and actual pre-commit pass. The hook leaves the tested tree unchanged.
  • Standard npm run check remains blocked by this host's missing /proc/self/exe. The loopback fixture is a simulated producer, not a real Chromium/browser session. No real browser, attached target, packaged-install or native-platform qualification is claimed.
Bounded discovery cost control

Same 31,171-byte, 300-target valid response; complete two-request production discovery and identical target-output digest. First-call elapsed/CPU: 28.0/52.3 ms before, 32.7/53.9 ms after. Median of three warm calls: 5.81/7.54 ms before, 6.15/7.67 ms after. Imports/startup, tokens and peak process-family memory are unmeasured. This small loopback sample is not a performance improvement or real-browser benchmark.

Compatibility, safety, and release

  • Breaking changes or migration steps: malformed UTF-8 that was previously replacement-decoded is now rejected. Valid UTF-8 needs no migration; no public command/schema changes.
  • Real Hopper/Ghidra, browser, or OS coverage: the local validation above uses loopback HTTP fixtures, not real engines or browsers. Hosted checks are separate evidence.
  • Package or release metadata impact: no package/version/generated-metadata edits.
  • Security, privacy, process, or containment review: validation occurs within the existing bounded response path; authorization, selected targets, deadlines, cancellation and cleanup are preserved. No new execution or mutation capability is added.

Author readiness

Human owner: @Afloat16

  • 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

The current template's additional pre-merge checklist is retained unchecked for final review; these boxes do not replace the existing initial-readiness declaration.

  • 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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/4524 **Author:** [@Afloat16](https://github.com/Afloat16) **Created:** 10/16/2026 **Status:** ✅ Merged **Merged:** 10/27/2026 **Merged by:** [@morluto](https://github.com/morluto) **Base:** `main` ← **Head:** `fix/cdp-discovery-utf8` --- ### 📝 Commits (2) - [`f68ed38`](https://github.com/morluto/rea/commit/f68ed3825ebca564e852e6955d348baa9f95395b) fix(browser): reject invalid UTF-8 in HTTP CDP discovery - [`cd289ba`](https://github.com/morluto/rea/commit/cd289bad4c6e51dc0755d5ff519ce73931dc113b) Merge upstream main into fix/cdp-discovery-utf8 ### 📊 Changes **2 files changed** (+102 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `src/browser/CdpEndpoint.ts` (+12 -3) 📝 `tests/boundary/browser/cdpEndpointResponseBounds.test.ts` (+90 -1) </details> ### 📄 Description ## Summary Reject malformed UTF-8 in HTTP CDP discovery responses before JSON decoding can replace source bytes. ## Problem and expected behavior HTTP CDP discovery currently decodes bytes with `Buffer.toString("utf8")` before parsing JSON. Malformed bytes inside a target title or URL become replacement characters and are accepted as different source values. Malformed UTF-8 must be rejected rather than silently changing a target title or URL. Valid Unicode, including a literal replacement character, remains valid. ## Change and scope Validate the complete, already size-bounded response with `node:buffer.isUtf8` before decoding. Reject malformed bytes using the existing `invalid_endpoint_response` error. Keep valid U+FFFD/multibyte strings and existing BOM/JSON handling unchanged. This affects HTTP discovery only; endpoint authorization, WebSocket framing, byte/time limits, cancellation and provider capabilities are unchanged. This is an ordinary validation fix within the existing HTTP discovery boundary; a separate new-provider or target-execution scope decision is not applicable. It follows the [contribution scope](https://github.com/morluto/rea/blob/main/CONTRIBUTING.md#contribution-scope). Related candidate inventory: https://github.com/morluto/rea/discussions/3847#discussioncomment-18942539. Current main and related open/closed issue/PR searches were checked before submission; no equivalent HTTP discovery UTF-8 fix was found. ## Contract and boundary impact - Semantic owner and earliest changed stage: `readCdpJson`, after complete size-bounded byte collection and before UTF-8 decoding/JSON parsing. - Contribution scope fit and linked maintainer decision: ordinary fix to an existing supported workflow; no new provider or execution capability. - CLI and MCP/tool-catalog contract: existing `list-browser-targets` / `list_browser_targets` return the existing `invalid_endpoint_response` failure for malformed discovery bytes. No command, schema or catalog entry is added. - Provider, bridge, target-format, or platform compatibility: HTTP CDP discovery only; the validation uses the pinned Node runtime's `node:buffer.isUtf8`. - Evidence, artifact, provenance, or reconstruction contract: reject corrupted source values instead of retaining replacement-decoded titles/URLs; valid returned target values remain unchanged. - Target selection, authority, upstream behavior, and cleanup details: discovery contacts the caller-selected HTTP endpoint through the existing authorization and cleanup path; no new attachment, script execution or mutation is introduced. - Generated metadata (`docs/public/product-catalog.json`), package, or installation impact: no authored contract/package/installation change and no generated outputs in this diff. Expected effects describe the production discovery operation, including its existing HTTP requests. Test runners and CLI/MCP subprocesses are validation activities. - [ ] 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. - [x] 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: malformed target-title/URL bytes, recovery on the next discovery, valid split multibyte text/literal U+FFFD and leading-BOM rejection in `cdpEndpointResponseBounds.test.ts`. - Base reproduction: the identical file fails twice on the recorded base and passes all nine tests with the fix, as detailed below. - User-visible CLI/MCP outcome: the recorded fresh compiled calls reject malformed title/URL and BOM inputs using the existing discovery error; valid split-Unicode input succeeds through both public adapters. - Remaining proof gaps: the loopback server is simulated; no local real-browser, attached-target, packaged-install or native-platform qualification is claimed. The results below belong to the recorded head/base, not today's main. For evidence-bearing changes: - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed Base: main `f4337864633ce3ac44bf4d0d888deeecb0722ea7`. This branch retains the existing fix and synchronizes that main without unrelated authored edits. - Identical discovery regression file: **2 failures / 7 passes on main; 9 passes after**. Covers damaged title/URL bytes, next-discovery recovery, split multibyte HTTP chunks, literal U+FFFD, BOM rejection and existing size/deadline/cancellation/status controls. - **38 related tests / 7 files pass**, including discovery authorization, browser-socket routing, target inventory, protocol failures and shared workflow/domain controls. - Fresh compiled `list-browser-targets` CLI and real SDK stdio `list_browser_targets` each pass **4 loopback HTTP cases**: malformed title, malformed URL, BOM, and valid split Unicode. Each public call is observed requesting both discovery endpoints. Four direct compiled discovery controls also pass. - Official `compile:termux`, TypeScript 6 checking, lint/module boundaries, knip, metadata, architecture/discovery, changed-file formatting and actual pre-commit pass. The hook leaves the tested tree unchanged. - Standard `npm run check` remains blocked by this host's missing `/proc/self/exe`. The loopback fixture is a simulated producer, **not a real Chromium/browser session**. No real browser, attached target, packaged-install or native-platform qualification is claimed. <details><summary>Bounded discovery cost control</summary> Same 31,171-byte, 300-target valid response; complete two-request production discovery and identical target-output digest. First-call elapsed/CPU: 28.0/52.3 ms before, 32.7/53.9 ms after. Median of three warm calls: 5.81/7.54 ms before, 6.15/7.67 ms after. Imports/startup, tokens and peak process-family memory are unmeasured. This small loopback sample is not a performance improvement or real-browser benchmark. </details> ## Compatibility, safety, and release - Breaking changes or migration steps: malformed UTF-8 that was previously replacement-decoded is now rejected. Valid UTF-8 needs no migration; no public command/schema changes. - Real Hopper/Ghidra, browser, or OS coverage: the local validation above uses loopback HTTP fixtures, not real engines or browsers. Hosted checks are separate evidence. - Package or release metadata impact: no package/version/generated-metadata edits. - Security, privacy, process, or containment review: validation occurs within the existing bounded response path; authorization, selected targets, deadlines, cancellation and cleanup are preserved. No new execution or mutation capability is added. ## Author readiness Human owner: @Afloat16 - [x] 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. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## Before merge The current template's additional pre-merge checklist is retained unchecked for final review; these boxes do not replace the existing initial-readiness declaration. - [ ] 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:13:17 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#6285
No description provided.