Repository navigation
fix(browser): block SSRF redirect bypass via real-time route interception - #58771
Conversation
sharkqwy
left a comment
There was a problem hiding this comment.
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:
- A TTL-based eviction (e.g. store
{ blockedAt: Date.now() }in aMapand periodically prune entries older than N minutes), or - 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.
There was a problem hiding this comment.
💡 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 SummaryThis 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 Key points:
Confidence Score: 5/5
Prompt To Fix All With AIThis 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 |
|
@greptile review |
|
I agree with moving the SSRF enforcement point into a real-time route interception layer, but I found two regressions that should be fixed.
|
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
|
@greptile review |
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
|
@codex review |
There was a problem hiding this comment.
💡 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".
562ec47 to
67c6e74
Compare
…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
…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
…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
…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
…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
…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
…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
…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
…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
Summary
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.page.goto(). Every top-level navigation request is checked in real time viaassertBrowserNavigationAllowed; 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.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause / Regression History (if applicable)
page.goto()follows redirects before Playwright exposes the redirect chain to the caller. Post-hoc inspection ofresponse.request().redirectedFrom()is too late — internal HTTP requests have already been sent.Regression Test Plan (if applicable)
extensions/browser/src/browser/pw-session.create-page.navigation-guard.test.tspage.close()is called once, andSsrFBlockedErroris thrown.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)
Security Impact (required)
Repro + Verification
Environment
Steps
createPageViaPlaywrightornavigateViaPlaywrightwith that URL.SsrFBlockedErrorthrown before any response is received from the internal host.Expected
SsrFBlockedErrorthrown immediately on the blocked redirect hop.BlockedBrowserTargetError.Actual (before fix)
Evidence
pw-session.create-page.navigation-guard.test.tsupdated to simulate route interception; assertspageClosecalled once)Human Verification (required)
listPagesViaPlaywright.request.frame()throwing returnstrue(conservative); double-close not possible; retry path does not re-attempt SSRF-blocked navigations.Review Conversations
Compatibility / Migration
Risks and Mitigations
"**"may intercept sub-frame navigations unexpectedly.isTopLevelNavigationRequestgates the policy check to main-frame navigation requests only; all other routes callroute.continue()unconditionally.page.unroutefailure infinallycould leave stale handlers.unrouteerrors are swallowed (.catch(() => {})); Playwright cleans up handlers when the page closes.