Skip to content

fix(browser): block SSRF redirect bypass via real-time route interception - #58771

Merged
jacobtomlinson merged 16 commits into
openclaw:mainfrom
pgondhi987:fix/fix-78
Apr 2, 2026
Merged

jacobtomlinson merged 16 commits into
openclaw:mainfrom
pgondhi987:fix/fix-78

Conversation

@pgondhi987

Copy link
Copy Markdown
Contributor

Summary

🤖 AI-assisted PR (generated by OpenAI Codex, reviewed by Claude)

  • Problem: The browser extension's navigation guard checked SSRF policy only after page.goto() completed, inspecting the redirect chain post-hoc. An attacker-controlled redirect through a private/internal IP could reach the internal host before the check fired.
  • Why it matters: A specially crafted URL with an intermediate redirect to a private IP could exfiltrate data from internal services via the browser tool before the policy blocked it.
  • What changed: Navigation is now gated by a Playwright route handler installed before page.goto(). Every top-level navigation request is checked in real time via assertBrowserNavigationAllowed; blocked requests are aborted immediately, the tab is closed, and the target is marked blocked for all subsequent tool calls (BlockedBrowserTargetError). Belt-and-suspenders post-navigation checks (assertPageNavigationCompletedSafely) are preserved.
  • What did NOT change: Sub-frame/resource requests are not intercepted; only top-level navigations are policy-gated. Retry logic for detached-frame errors is unchanged. No changes to the SSRF policy rules themselves.

Change Type (select all)

  • Bug fix
  • Security hardening

Scope (select all touched areas)

  • Integrations

Linked Issue/PR

  • This PR fixes a bug or regression

Root Cause / Regression History (if applicable)

  • Root cause: page.goto() follows redirects before Playwright exposes the redirect chain to the caller. Post-hoc inspection of response.request().redirectedFrom() is too late — internal HTTP requests have already been sent.
  • Missing detection / guardrail: No per-request interception before the HTTP request was dispatched.
  • Prior context: Navigation guard was added to check final URLs and redirect chains; the interception-layer approach was not used at the time.
  • Why this regressed now: N/A — original guard was never sufficient for mid-redirect blocking.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Seam / integration test
  • Target test or file: extensions/browser/src/browser/pw-session.create-page.navigation-guard.test.ts
  • Scenario the test should lock in: A URL with a private-IP intermediate redirect hop is blocked, page.close() is called once, and SsrFBlockedError is thrown.
  • Why this is the smallest reliable guardrail: Tests the exact route-handler callback path without a live browser.
  • Existing test that already covers this (if any): Test existed but only verified post-hoc redirect-chain check; updated to simulate real-time route handler interception.
  • If no new test is added, why not: N/A — test was updated.

User-visible / Behavior Changes

None for safe navigations. For navigations that previously slipped through via redirect, they now fail fast with an error and the tab is permanently closed for that session.

Diagram (if applicable)

Before:
[goto(url)] -> [redirect to 127.0.0.1] -> [request reaches internal host] -> [post-hoc check blocks]

After:
[route handler installed] -> [goto(url)] -> [redirect to 127.0.0.1 intercepted] -> [abort + close tab] -> [BlockedBrowserTargetError on any future access]

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No — the fix prevents network calls to blocked destinations
  • Command/tool execution surface changed? No
  • Data access scope changed? No
  • Risk + mitigation: Route handler fires synchronously in Playwright's request interception pipeline; aborting the route prevents the HTTP request from completing to the internal host.

Repro + Verification

Environment

  • OS: Linux
  • Runtime/container: Node 22 / Bun
  • Model/provider: N/A
  • Integration/channel: Browser extension (Playwright/CDP)

Steps

  1. Configure a URL that redirects through a private IP mid-chain.
  2. Invoke createPageViaPlaywright or navigateViaPlaywright with that URL.
  3. Observe SsrFBlockedError thrown before any response is received from the internal host.

Expected

  • SsrFBlockedError thrown immediately on the blocked redirect hop.
  • Tab closed; subsequent tool calls to the same target throw BlockedBrowserTargetError.

Actual (before fix)

  • Navigation completed to the final URL; policy check fired after internal request was already sent.

Evidence

  • Failing test/log before + passing after (pw-session.create-page.navigation-guard.test.ts updated to simulate route interception; asserts pageClose called once)

Human Verification (required)

  • Verified scenarios: Route handler fires for top-level navigations; sub-frame requests pass through; blocked targets are excluded from listPagesViaPlaywright.
  • Edge cases checked: request.frame() throwing returns true (conservative); double-close not possible; retry path does not re-attempt SSRF-blocked navigations.
  • What you did not verify: Live browser round-trip against a real redirect server.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Risks and Mitigations

  • Risk: Route handler on "**" may intercept sub-frame navigations unexpectedly.
    • Mitigation: isTopLevelNavigationRequest gates the policy check to main-frame navigation requests only; all other routes call route.continue() unconditionally.
  • Risk: page.unroute failure in finally could leave stale handlers.
    • Mitigation: unroute errors are swallowed (.catch(() => {})); Playwright cleans up handlers when the page closes.

@sharkqwy sharkqwy left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review: SSRF redirect bypass fix via route interception

Good approach — moving from post-hoc redirect chain inspection to real-time Playwright route interception is the right call for closing the TOCTOU gap where a redirect could land on a private IP before the after-the-fact check fires.

Potential issue: unbounded blockedTargetsByCdpUrl growth

The module-level Set<string> at blockedTargetsByCdpUrl is only cleared when closePlaywrightBrowserConnection is called. In a long-lived gateway process that blocks many targets over time (e.g. an agent iterating over user-supplied URLs), this set will grow without bound.

Consider either:

  1. A TTL-based eviction (e.g. store { blockedAt: Date.now() } in a Map and periodically prune entries older than N minutes), or
  2. A cap on the set size (LRU eviction after e.g. 1000 entries)

In practice this is probably low-severity since each entry is a small string key, but it's worth a comment or a TODO so it doesn't silently accumulate in production.

Minor: clearBlockedTargetsForCdpUrl iterates-and-deletes

for (const key of blockedTargetsByCdpUrl) {
  if (key.startsWith(prefix)) {
    blockedTargetsByCdpUrl.delete(key);
  }
}

This is safe in JS (Set iteration tolerates concurrent deletion), but a brief inline comment would prevent future contributors from "fixing" it. Alternatively, collect keys first then bulk-delete.

Tests look solid

The mock routeHandler approach in the navigation guard test properly simulates the interception flow, and the blocked-target assertions in pw-tools-core.snapshot tests cover the key paths. Nice work on the test harness additions with gotoPageWithNavigationGuard and assertPageNavigationCompletedSafely mocks.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8a39ef1800

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@greptile-apps

greptile-apps Bot commented Apr 1, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes an SSRF redirect-bypass vulnerability in the browser extension by moving SSRF policy enforcement from a post-navigation, post-hoc redirect-chain inspection into a real-time Playwright route handler installed before page.goto(). Any top-level navigation request (including mid-chain redirects) is now checked via assertBrowserNavigationAllowed before the HTTP request is dispatched; blocked requests abort the route immediately, quarantine the tab via a new blockedTargetsByCdpUrl set, and cause all future tool calls to that target to throw BlockedBrowserTargetError. Belt-and-suspenders post-navigation checks (assertPageNavigationCompletedSafely) are preserved.

Key points:

  • gotoPageWithNavigationGuard (new) installs a "**" route handler gated on isTopLevelNavigationRequest so only main-frame navigations are policy-checked; sub-frame/resource requests pass through unconditionally.
  • blockedTargetsByCdpUrl (module-level Set) survives forced reconnects but is cleared on natural browser disconnect (correct — old target IDs are no longer valid after a crash/reconnect).
  • errors.ts uses a name-based check for BlockedBrowserTargetError (returning 409) rather than instanceof to avoid a circular import with pw-session.ts.
  • Test coverage is extensive: 8 new scenarios in pw-session.create-page.navigation-guard.test.ts covering blocked hops, preserved tabs on non-SSRF failures, close failures with quarantine preserved, and quarantine surviving forceDisconnect.
  • One minor hardening opportunity: when assertBrowserNavigationAllowed throws a non-policy (transient) error inside the route handler, the handler re-throws without explicitly calling route.abort(). This relies on Playwright's implicit "abort unresolved routes" behaviour, which is correct in current Playwright versions but not guaranteed by the public API contract. Calling route.abort().catch(() => {}) before re-throwing would make the intent explicit and guard against future Playwright behaviour changes.

Confidence Score: 5/5

  • Safe to merge — the security fix is sound and well-tested; the one remaining finding is a minor defensive hardening suggestion with no impact under current Playwright behaviour.
  • All previously raised concerns have been addressed. The single remaining P2 finding (missing explicit route.abort() before re-throwing non-policy handler errors) does not represent a current defect: Playwright aborts unresolved routes when the handler throws, and in the transient-DNS-error scenario the browser-level DNS failure would independently prevent SSRF anyway. No P0 or P1 issues remain.
  • No files require special attention beyond the minor suggestion on pw-session.ts lines 724–731.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: extensions/browser/src/browser/pw-session.ts
Line: 724-731

Comment:
**Unhandled route not explicitly aborted before re-throwing**

When `assertBrowserNavigationAllowed` throws a non-policy error (e.g. a transient DNS error during a hostname-to-IP policy lookup), the handler re-throws without calling `route.abort()` or `route.continue()`. Playwright's documented behaviour when a route handler throws without resolving the route is to abort the request, but this is an implicit implementation detail that has varied across versions. If Playwright lets the request proceed instead, a navigation targeting a hostname whose SSRF-safety check threw transiently could still reach a private host.

Defensive practice is to explicitly abort before re-throwing:

```suggestion
    } catch (err) {
      if (isPolicyDenyNavigationError(err)) {
        blockedError = err;
        await route.abort().catch(() => {});
        return;
      }
      await route.abort().catch(() => {});
      throw err;
    }
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (3): Last reviewed commit: "fix: address review-pr skill feedback" | Re-trigger Greptile

@pgondhi987

Copy link
Copy Markdown
Contributor Author

@greptile review

@jacobtomlinson jacobtomlinson self-assigned this Apr 1, 2026
@jacobtomlinson

jacobtomlinson commented Apr 1, 2026 •

Copy link
Copy Markdown
Contributor

I agree with moving the SSRF enforcement point into a real-time route interception layer, but I found two regressions that should be fixed.

  1. createPageViaPlaywright() now propagates ordinary page.goto() failures instead of still returning the created tab (extensions/browser/src/browser/pw-session.ts:936; this changed behavior from the old page.goto(...).catch(() => null) path on main).
  2. The new BlockedBrowserTargetError is thrown from Playwright tab lookups but is not mapped through toBrowserErrorResponse() / mapTabError(), so follow-up operations on quarantined tabs can leak as generic 500s (extensions/browser/src/browser/pw-session.ts:175, extensions/browser/src/browser/errors.ts:68, extensions/browser/src/browser/server-context.ts:227).

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d83c1eb61b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2a14aca56c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8b0e3a3268

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 027ab84347

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4831882b5b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@pgondhi987

Copy link
Copy Markdown
Contributor Author

@greptile review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3b62b4edd7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dfcb85daa1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7bad2a018f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@pgondhi987

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4917c7b2d2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@jacobtomlinson
jacobtomlinson merged commit 462b402 into openclaw:main Apr 2, 2026
7 checks passed
ngutman pushed a commit that referenced this pull request Apr 3, 2026
…tion (#58771)

Install a Playwright route handler before `page.goto()` so navigations
to private/internal IPs are intercepted and aborted mid-redirect instead
of being checked post-hoc after the request already reached the internal
host. Blocked targets are permanently marked and rejected for subsequent
tool calls.

Thanks @pgondhi987
steipete pushed a commit to duncanita/openclaw that referenced this pull request Apr 4, 2026
…tion (openclaw#58771)

Install a Playwright route handler before `page.goto()` so navigations
to private/internal IPs are intercepted and aborted mid-redirect instead
of being checked post-hoc after the request already reached the internal
host. Blocked targets are permanently marked and rejected for subsequent
tool calls.

Thanks @pgondhi987
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
…tion (openclaw#58771)

Install a Playwright route handler before `page.goto()` so navigations
to private/internal IPs are intercepted and aborted mid-redirect instead
of being checked post-hoc after the request already reached the internal
host. Blocked targets are permanently marked and rejected for subsequent
tool calls.

Thanks @pgondhi987
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…tion (openclaw#58771)

Install a Playwright route handler before `page.goto()` so navigations
to private/internal IPs are intercepted and aborted mid-redirect instead
of being checked post-hoc after the request already reached the internal
host. Blocked targets are permanently marked and rejected for subsequent
tool calls.

Thanks @pgondhi987
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
…tion (openclaw#58771)

Install a Playwright route handler before `page.goto()` so navigations
to private/internal IPs are intercepted and aborted mid-redirect instead
of being checked post-hoc after the request already reached the internal
host. Blocked targets are permanently marked and rejected for subsequent
tool calls.

Thanks @pgondhi987
Nachx639 pushed a commit to Nachx639/clawdbot that referenced this pull request Jun 17, 2026
…tion (openclaw#58771)

Install a Playwright route handler before `page.goto()` so navigations
to private/internal IPs are intercepted and aborted mid-redirect instead
of being checked post-hoc after the request already reached the internal
host. Blocked targets are permanently marked and rejected for subsequent
tool calls.

Thanks @pgondhi987
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
…tion (openclaw#58771)

Install a Playwright route handler before `page.goto()` so navigations
to private/internal IPs are intercepted and aborted mid-redirect instead
of being checked post-hoc after the request already reached the internal
host. Blocked targets are permanently marked and rejected for subsequent
tool calls.

Thanks @pgondhi987
globalcaos pushed a commit to globalcaos/tinkerclaw that referenced this pull request Sep 29, 2026
…tion (openclaw#58771)

Install a Playwright route handler before `page.goto()` so navigations
to private/internal IPs are intercepted and aborted mid-redirect instead
of being checked post-hoc after the request already reached the internal
host. Blocked targets are permanently marked and rejected for subsequent
tool calls.

Thanks @pgondhi987
lhfer pushed a commit to lhfer/openclaw that referenced this pull request Oct 11, 2026
…tion (openclaw#58771)

Install a Playwright route handler before `page.goto()` so navigations
to private/internal IPs are intercepted and aborted mid-redirect instead
of being checked post-hoc after the request already reached the internal
host. Blocked targets are permanently marked and rejected for subsequent
tool calls.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants