Skip to content

fix(browser): preserve native CORS preflights - #185028

Merged
eleqtrizit merged 7 commits into
openclaw:mainfrom
eleqtrizit:1129
Oct 29, 2026
Merged

eleqtrizit merged 7 commits into
openclaw:mainfrom
eleqtrizit:1129

Conversation

@eleqtrizit

@eleqtrizit eleqtrizit commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Browser navigation guards used Playwright catch-all page routing, which made Chromium treat intercepted CORS preflights as permissive and could send a cross-origin request the destination rejected. This change moves guard handling into document-only CDP interception, preserves native CORS, and explicitly cancels a committed timed-out page opening while retiring successful committed document ownership without canceling healthy response bodies or child loads. It preserves the invocation-scoped navigation policy introduced by #104254 and does not depend on the unmerged policy-removal proposal in #167703.

What Problem This Solves

  1. In extensions/browser/src/browser/pw-session-navigation.ts, guarded actions and guarded goto used catch-all Playwright routing. Playwright could synthesize a successful CORS preflight, so a rejecting destination received the non-simple PUT.

  2. In extensions/browser/src/browser/pw-session-navigation-fence.ts, the existing operation-owned fence tracked document redirects and out-of-process frames but did not own the route handler or limit Fetch interception to documents.

  3. The first document-only implementation waited for a terminal Network event after a committed streamed document timed out. Chromium does not consistently emit that event after Page.stopLoading, so cleanup could replace the original Playwright TimeoutError and close a usable committed tab.

  4. A successful action could also return before delayed response headers committed streaming main-frame HTML. Cleanup sampled commitment once, then waited 20 seconds even after the later commit, failed, and retained interception until page close, so later navigation on the otherwise usable tab was aborted.

  5. Successful action cleanup also used page-wide stopLoading after main-frame commit, truncating healthy delayed finite HTML and simultaneous child loads. Ownership now retires independently at each document commit; failure and cancellation still stop loading.

The net effect was excess page-script network authority before this fix plus committed-page recovery and successful-load regressions in its first revisions.

Why this design

  • Intercept only Document resources through the operation-owned CDP session; leave preflights and subresources on Chromium's native network path.
  • Keep top-level/subframe checks, redirect/OOPIF ownership, and live invocation authority in one fence.
  • Establish a same-target protocol barrier before cleanup so a queued document cannot escape interception.
  • On navigation failure, acknowledge Page.stopLoading, settle the fence's owned document state, and preserve the original navigation error.
  • Retire each document at its own frame commit, including OOPIF sessions: committed responses cannot redirect, so their bodies can continue while uncommitted redirect chains and policy work remain fenced. Reserve page-wide stopLoading for failure or cancellation.
  • Disable Fetch before detaching and retain interception when cancellation cannot be confirmed.
  • Add no setting, dependency, public API, or migration surface.

Why this does not conflict with related browser-navigation work

PR Governed layer Relation to this PR
#104254 Invocation-scoped document policy for browser actions The base includes it. This PR preserves its policy and changes only the interception mechanism and cleanup.
#167703 Unmerged proposal to retire native navigation-policy enforcement This PR keeps the current contract and does not depend on that proposal.

The shared navigation files compose with the existing policy: this branch narrows interception and repairs cleanup without redefining the allowed destinations.

Evidence

Path × mode Final-effect observation Reproducible command and result
Original catch-all route mechanism With no route, rejected CORS sent OPTIONS only; with the base catch-all page.route("**", route.fallback) mechanism, the same rejecting destination received PUT and no OPTIONS. node /tmp/openclaw-1129-probe/probe.mjs against pinned playwright-core 1.64.1 reproduced the before/without-route differential shown below.
Guarded action; destination rejects CORS Destination recorded OPTIONS and zero PUT requests. pnpm test:live -- extensions/browser/src/browser/pw-session-navigation-cors.live.test.ts — rejected action case passed.
Guarded goto; destination rejects CORS Destination recorded OPTIONS and zero PUT requests. Same command — rejected goto case passed.
Guarded action; destination consents Destination recorded OPTIONS, then exactly one PUT. Same command — consenting case passed.
Denied document The attempted 127.0.0.2 fixture destination recorded zero document requests under a policy allowing only 127.0.0.1; source URL and title remained unchanged. Same command — denied-document/source-preservation case passed.
Allowed redirects across main frame and OOPIF Each allowed goto/action/early-return/existing/new/nested-frame case recorded exactly one destination request. pnpm test:live -- extensions/browser/src/browser/pw-session-navigation-authority.live.test.ts — allowed cases 6/6.
Revoked redirects across main frame and OOPIF Each revoked case rejected with the authority error and recorded zero destination requests; a subsequent new owner navigated successfully. Same command — revoked cases 6/6.
Shipped create-page streamed timeout createPageViaPlaywright returned the committed tab after the 1-second timeout; URL, title Committed stream, and body ready remained usable. pnpm test:live -- extensions/browser/src/browser/pw-session-create-page-timeout.live.test.ts — 1/1 passed.
Committed action stream The guarded action returned before the fixture's one-second-delayed response headers, cleanup observed the later main-frame commit, completed without response EOF, retained URL/title/body, and a subsequent navigation succeeded. The earlier reviewed implementation failed the immediate-header variant after 20.1 seconds. CORS live suite delayed-commit streamed-action case passed in 1.176 seconds.
Successful action; delayed finite main HTML and simultaneous child response At action return both response tails were absent; afterward the main form, child tail, late script/title, and page load completed. Original production failed waiting for load at 5 seconds; repaired production passes. CORS live regression: preserves delayed finite HTML and simultaneous pending child loads after success. All three browser live suites passed 18/18; acceptance 75/75.
Unit and repository gates Fence lifecycle/create-page tests passed 45/45; the connection-owner acceptance set passed 75/75 after migrating its CDP fixture; format, production/test types, scoped type-aware lint, structural guards, and import-cycle checks passed. pnpm exec vitest run --config test/vitest/vitest.extension-browser.config.ts ... and OPENCLAW_CHECK_CHANGED_SKIP_DEADCODE=1 node scripts/check-changed.mjs --base upstream/main.

The sink observations come from fixture HTTP-server request counters and the real Chromium page's committed URL/title/body; fixtures use loopback only and contain no credentials or private endpoints. The redacted current-head terminal trace below comes directly from opt-in output after each sink assertion.

Original base-mechanism differential (real Chromium)
Chromium 153.0.8010.12
{"guarded":false,"allow":false,"result":"rejected TypeError","targetReceived":["OPTIONS /deny-false"]}
{"guarded":false,"allow":true,"result":"resolved 200","targetReceived":["OPTIONS /allow-false","PUT /allow-false"]}
{"guarded":true,"allow":false,"result":"rejected TypeError","targetReceived":["PUT /deny-true"]}
{"guarded":true,"allow":true,"result":"resolved 200","targetReceived":["PUT /allow-true"]}

Here guarded=true installs the original base's exact catch-all Playwright route/fallback mechanism; the rejecting destination receiving PUT is the regression this PR removes.

Real-Chromium terminal proof (current head)
[browser-proof] successfulAction pendingMain=true pendingChild=true delayedMain=complete delayedChild=complete load=complete
[browser-proof] cors owner=action methods=OPTIONS put=0
[browser-proof] cors owner=goto methods=OPTIONS put=0
[browser-proof] cors consenting=OPTIONS,PUT deniedDocuments=0 sourcePreserved=true
[browser-proof] redirects owner=goto revoke=false sourceRequests=1 guardedDestinationRequests=1 subsequentOwner=not-needed
[browser-proof] redirects owner=goto revoke=true sourceRequests=1 guardedDestinationRequests=0 subsequentOwner=succeeded
[browser-proof] redirects owner=selected-page action revoke=false sourceRequests=1 guardedDestinationRequests=1 subsequentOwner=not-needed
[browser-proof] redirects owner=selected-page action revoke=true sourceRequests=1 guardedDestinationRequests=0 subsequentOwner=succeeded
[browser-proof] redirects owner=early-returning action revoke=false sourceRequests=1 guardedDestinationRequests=1 subsequentOwner=not-needed
[browser-proof] redirects owner=early-returning action revoke=true sourceRequests=1 guardedDestinationRequests=0 subsequentOwner=succeeded
[browser-proof] redirects owner=existing iframe revoke=false sourceRequests=1 guardedDestinationRequests=1 subsequentOwner=not-needed
[browser-proof] redirects owner=existing iframe revoke=true sourceRequests=1 guardedDestinationRequests=0 subsequentOwner=succeeded
[browser-proof] redirects owner=new iframe revoke=false sourceRequests=1 guardedDestinationRequests=1 subsequentOwner=not-needed
[browser-proof] redirects owner=new iframe revoke=true sourceRequests=1 guardedDestinationRequests=0 subsequentOwner=succeeded
[browser-proof] redirects owner=nested iframe revoke=false sourceRequests=1 guardedDestinationRequests=1 subsequentOwner=not-needed
[browser-proof] redirects owner=nested iframe revoke=true sourceRequests=1 guardedDestinationRequests=0 subsequentOwner=succeeded
[browser-proof] stream committed=true subsequentNavigation=true

Test Files  3 passed (3)
Tests       18 passed (18)

Boundary decisions requested from browser owners

  1. Confirm that document-only interception remains the intended owner for top-level and OOPIF navigation policy while Chromium owns CORS and subresources.
  2. Confirm that per-document commit retires successful response ownership without canceling its body, while acknowledged top-level Page.stopLoading remains the failure/cancellation boundary for retaining a usable committed tab.

Testing

  • Added pw-session-navigation-cors.live.test.ts for rejected/consenting CORS and denied-document source preservation.
  • Extended it with delayed-header infinite-stream recovery and delayed finite HTML plus simultaneous child-body completion proof, with opt-in redacted sink traces.
  • Added pw-session-create-page-timeout.live.test.ts through the shipped createPageViaPlaywright entry point.
  • Re-ran pw-session-navigation-authority.live.test.ts for allowed and revoked redirects across main-frame and OOPIF paths (12/12).
  • Updated the fence lifecycle suite and removed two mock cases that no longer exercised their named failures.
  • Migrated pw-session.connections.test.ts from the removed route rendezvous to an EventEmitter-backed CDP session and Fetch.enable interception rendezvous; Clawsweeper's exact four-file acceptance command passed 75/75.
  • Focused unit suites passed 45/45; all 18 live Chromium cases passed.
  • Scoped changed-file gate passed against upstream/main; the documented dead-code skip applies only to an unrelated full-tree finding.

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 26, 2026
@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR replaces catch-all Playwright routing with document-only CDP interception and preserves healthy response bodies during successful cleanup.

Example: A guarded page sends a cross-origin PUT to a destination that rejects its CORS preflight.

  • Before: The catch-all route lets the destination receive PUT without OPTIONS.
  • After: Chromium sends OPTIONS and prevents PUT.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful and coherent repair with real-browser final-effect evidence; the previous blocker is resolved, while broad exact-head CI remains unexercised in this draft.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): Real Chromium and fixture HTTP servers exercise the changed production navigation owners: rejected preflights yield zero PUT requests, consenting requests succeed, denied documents and revoked main-frame/OOPIF redirects reach no destination, later owners recover, and successful delayed main and child responses finish intact. The create-page trace also covers committed timeout recovery. Prepared screenshots were inspected but show panel layout rather than these network behaviors; the terminal sink traces supply the relevant proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Guarded browsing can send cross-origin writes that Chromium's native CORS policy would prevent.
Reason: The demonstrated network-boundary defect warrants repair, and the maintainer-authored direction preserves existing navigation policy.

Merge readiness

✅ Ready for maintainer review

This PR fixes a concrete CORS boundary defect still present on main; the latest revision resolves the previous unfinished-load finding, and no new actionable defect was found.

Priority: P2
Reviewed head: c8f7204b32b3d577c39b81db8400093d4156c0ec

Before merge

None.

Findings

None.

Agent review details

How this fits together

The browser plugin wraps Playwright navigation and actions with document policy checks; admitted documents reach Chromium while CORS and subresources retain native browser handling.

flowchart TD
  A[Browser operation] --> B[Navigation guard]
  B --> C[Document CDP fence]
  C --> D[Policy and live authority]
  D --> E[Chromium document request]
  A --> F[Native CORS and subresources]
  E --> G[Commit and cleanup]
Loading

Technical review

Best possible solution:

Use the existing CDP fence as the single document-interception owner, preserve native CORS, and retire committed responses without canceling healthy loads.

Do we have a high-confidence way to reproduce the issue?

Current main contains the reported catch-all route mechanism, and the supplied real-Chromium differential shows it sends PUT to a destination that rejects native preflight; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The change repairs the owning interception boundary, removes the replaced route path, and preserves the established policy and cleanup contracts without adding configuration or persistence.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 52e1c75ed3e3.

Provenance checked

  • Invocation-scoped document navigation policy keeps the original intent (fix(browser): block interaction-triggered navigation SSRF #104254: Reject policy-denied interaction navigation before HTTP request bytes are sent while preserving the source page and stopping subsequent action effects.)
  • Redirect and OOPIF authority fence keeps the original intent (0901c1d: Enforce live invocation authority across redirect hops and independently hosted frame targets for managed local-preview navigation.)
  • Interception cleanup and error precedence keeps the original intent (fix(browser): clean up failed guarded navigation routes #113753: Remove failed interception ownership, expose cleanup failures on live pages, and preserve original navigation errors and quarantine.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 0901c1d adds extensions/browser/src/browser/pw-session-navigation.ts:308 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 0901c1d787e3; files: extensions/browser/src/browser/pw-session-navigation.ts)
  • LLagoon3: Raw commit c3aeedf adds extensions/browser/src/browser/pw-session-navigation.ts:334 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: c3aeedf0b4ed; files: extensions/browser/src/browser/pw-session-navigation.ts)

PR surface

Source +64, Tests +464. Total +528 across 9 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 2 160 96 +64
Tests 7 615 151 +464
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 775 247 +528

Review metrics

Metric Value Why it matters
Production versus test LOC Production +160/-96; tests +615/-151 Production growth implements document-only interception and commit-aware cleanup inside the existing fence; tests cover distinct CORS, authority, streaming, timeout, and consumer-lifecycle failures.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: A focused browser boundary repair prevents unintended cross-origin writes while preserving navigation and response loading.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (7 earlier review cycles)
  • reviewed 2026-10-26T21:27:27.058Z sha dee8d4f :: needs real behavior proof before merge. :: [P2] Preserve committed-tab recovery when document loading times out
  • reviewed 2026-10-26T22:05:39.850Z sha 65a51b1 :: needs real behavior proof before merge. :: [P2] Settle committed streaming documents in guarded actions
  • reviewed 2026-10-26T23:43:33.483Z sha e9f5c3d :: needs real behavior proof before merge. :: [P2] Recheck main-frame commitment while cleanup waits | [P2] Observe the destination used by the denied navigation
  • reviewed 2026-10-26T23:58:02.863Z sha cb54bd4 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-27T00:07:56.196Z sha cb54bd4 :: needs changes before merge. :: [P2] Migrate the remaining connection-owner navigation fixture
  • reviewed 2026-10-28T01:32:23.181Z sha 0e69bae :: needs changes before merge. :: [P2] Preserve unfinished page loads after successful actions
  • reviewed 2026-10-28T03:07:00.568Z sha 0e69bae :: needs changes before merge. :: [P2] Preserve unfinished loads after successful actions

Reviewed October 28, 2026, 5:38 PM ET / 21:38 UTC (Revision 8).

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 26, 2026
@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 26, 2026
@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus

obviyus commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot removed the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Oct 28, 2026
@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 28, 2026
@eleqtrizit

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 28, 2026
@eleqtrizit

Copy link
Copy Markdown
Contributor Author

Merge record

Summary: Replaces catch-all Playwright routing with document-only CDP interception, restoring native CORS preflights while retaining navigation-policy enforcement. Successful cleanup preserves healthy main-frame and child response bodies.

Decision Reason for Merge: Merged because Clawsweeper’s exact-head review found no actionable findings or before-merge blockers, supported by passing real-Chromium network and lifecycle regression tests.

Compatibility Checks Done: Acceptance tests passed 75/75 and live Chromium tests passed 18/18. Production/test types, scoped lint, formatting, and compatibility review passed; no configuration, public API, dependency, or migration changes. Broad CI remains skipped while draft; newly triggered required checks will be checked after marking ready.

@eleqtrizit
eleqtrizit marked this pull request as ready for review October 28, 2026 23:27
@eleqtrizit
eleqtrizit merged commit ae3561e into openclaw:main Oct 29, 2026
98 checks passed
@eleqtrizit
eleqtrizit deleted the 1129 branch October 29, 2026 19:23
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 30, 2026
* fix(browser): preserve native CORS preflights

* fix(browser): preserve committed timeout recovery

* fix(browser): settle committed action streams

* fix(browser): recheck streaming commits during cleanup

* test(browser): migrate navigation owner fixture

* fix(browser): preserve committed document bodies after successful actions

* test(browser): migrate dashboard navigation fixture to CDP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: browser P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants