Repository navigation
[fix]: harden domain policy setting - #3387
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: 33ea536 The changes in this PR will be included in the next version bump. This PR includes changesets to release 23 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 15 files
Architecture diagram
sequenceDiagram
participant SW as Service Worker
participant RT as StagehandRuntime
participant BC as BrowserContext
participant DNR as DomainPolicyDnrManager
participant CDP as CDP Connection
participant Chrome as Chrome DNR Engine
participant Ext as Extension Backend
Note over SW,Ext: Browser-wide Domain Policy Enforcement Architecture
Note over SW,Chrome: Startup: Session Rule Management
SW->>DNR: openSession()
DNR->>Chrome: getSessionRules()
Chrome-->>DNR: Existing rules
DNR->>Chrome: Clean abandoned policy rules
DNR-->>SW: DomainPolicyRuleSession
SW->>BC: BrowserContext.create(domainPolicyRules)
Note over RT,Chrome: Runtime: Domain Policy Enforcement
RT->>BC: setDomainPolicy(policy)
BC->>DNR: replace(normalizedPolicy)
DNR->>DNR: Compile rules (allow/block priorities)
DNR->>Chrome: isRegexSupported() validation
alt Regex supported
DNR->>Chrome: updateSessionRules(remove/add)
Chrome-->>DNR: Rules installed atomically
DNR-->>BC: Success
BC->>BC: Publish new policy state
else Regex rejected
Chrome-->>DNR: Validation error
DNR-->>BC: Error (rules retained)
BC-->>RT: Throw error
end
Note over Chrome,Ext: Request Flow (Browser-wide)
Chrome->>Chrome: Match URL against DNR rules
alt Blocking rule matches
Chrome->>Chrome: Block request before network
else Extension backend request (own extension, no tab)
Chrome->>Ext: Allow (priority 4 exemption rule)
else Allowed domain
Chrome->>Chrome: Allow (priority 2)
Chrome-->>Ext: Request proceeds
else Default block (allowlist mode)
Chrome->>Chrome: Block (priority 1)
end
Note over RT,Chrome: Disposal: Policy Cleanup
RT->>RT: disposeStagehandInstance()
RT->>BC: setDomainPolicy(null)
BC->>DNR: replace(null)
DNR->>Chrome: updateSessionRules(remove all owned)
Chrome-->>DNR: Rules cleared
DNR-->>BC: Cleanup complete
BC-->>RT: Policy cleared (before browser reuse)
Note over BC,DNR: Session Closure (retryable cleanup)
BC->>BC: close()
BC->>CDP: Disconnect
BC->>DNR: close()
alt Cleanup fails
DNR-->>BC: Error (rules retained)
BC-->>BC: Make retryable
Note over BC: Next close() retries cleanup
else Cleanup succeeds
DNR->>Chrome: Remove all policy rules
Chrome-->>DNR: Confirmed
DNR-->>BC: Closed
end
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
Contributor
There was a problem hiding this comment.
No issues found across 16 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Architecture diagram
sequenceDiagram
participant SW as Service Worker
participant RPC as RPC Client
participant RT as StagehandRuntime
participant DC as DomainPolicyDnrManager
participant BC as BrowserContext
participant DNR as chrome.declarativeNetRequest
participant CDP as CDP Connection
participant Browse as Browser Activity
Note over SW,DNR: Domain Policy Enforcement Flow
SW->>RT: createInstance(session)
RT->>DC: openSession()
DC->>DNR: getSessionRules()
DNR-->>DC: existing rules
DC->>DNR: updateSessionRules(remove stale owned)
DC-->>RT: DomainPolicyRuleSession
RPC->>BC: setDomainPolicy(domainPolicy)
BC->>DC: replace(normalizedPolicy)
DC->>DNR: isRegexSupported(regex checks)
alt Regex supported
DC->>DNR: updateSessionRules(addRules, remove old)
DNR-->>DC: success
DC-->>BC: rules installed
BC->>BC: Update domainPolicy state
else Regex not supported
DNR-->>DC: validation error
DC-->>BC: throw, retain old policy
end
Note over Browse,DNR: Enforcement (browser-wide, any tab/worker)
Browse->>DNR: Request to blocked/allow domain
alt Allowed by policy
DNR-->>Browse: allow request
else Blocked by policy
DNR-->>Browse: block request
end
Note over SW,RT: Instance Disposal
RPC->>RT: disposeStagehandInstance()
RT->>BC: setDomainPolicy(null)
BC->>DC: replace(null)
DC->>DNR: updateSessionRules(remove owned rules)
alt Cleanup fails
DNR-->>DC: reject
DC-->>BC: throw
BC-->>RT: error, keep policy state
RT-->>RPC: reject, retryable
else Cleanup success
DC-->>RT: rules removed
RT->>RT: clearInstance state
RT-->>RPC: complete
end
Note over RT,BC: Connection Replacement
RT->>RT: runPendingSessionCleanup()
RT->>BC: close()
BC->>DC: close()
DC->>DNR: remove owned rules
BC-->>RT: closed
RT->>RT: create new BrowserContext
alt New context bootstrap fails
RT->>BC: close()
BC->>DC: close()
end
akeimach
approved these changes
Nov 4, 2026
This was referenced Nov 4, 2026
miguelg719
pushed a commit
that referenced
this pull request
Nov 4, 2026
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @browserbasehq/[email protected] ### Minor Changes - [#3305](#3305) [`aeb1ba0`](aeb1ba0) Thanks [@miguelg719](https://github.com/miguelg719)! - add `browser.disconnect()`, which closes an attached Stagehand instance and the connection to a browser without closing the browser or releasing its Browserbase session (Browserbase still ends sessions without `keepAlive` on disconnect). `browser.close()` after `disconnect()` now throws (connect again to close the browser), a launched local browser receives `Browser.close` before it is terminated, browser handles expose `cdpUrl` (`cdp_url` in Python) for local browsers, and `connected` reports whether the handle still has a live connection - [#3325](#3325) [`d59afde`](d59afde) Thanks [@miguelg719](https://github.com/miguelg719)! - Add an extension watchdog for lost SDK clients ### Patch Changes - [#3339](#3339) [`44d99df`](44d99df) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - Adopt cross-origin iframes that were already loaded when Stagehand attached, or that are nested inside another cross-origin iframe, so snapshots and actions can reach them. - [#3330](#3330) [`dc8eb40`](dc8eb40) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - bump zod to 4.6.6 - [#3340](#3340) [`edb76b0`](edb76b0) Thanks [@akeimach](https://github.com/akeimach)! - Fix act, observe and extract with Claude Opus 5.5 by bumping `@ai-sdk/anthropic` and `ai` in the extension. - [#3387](#3387) [`066e875`](066e875) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fixed domain policy bypasses involving URLs with credentials, background requests, and speculative page loads - [#3383](#3383) [`1e50db6`](1e50db6) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - skip variable substitution for drag-and-drop arguments in act(). - [#3388](#3388) [`18b96f2`](18b96f2) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix issue where calling act() prevents cross-origin iframes from loading ## @browserbasehq/[email protected] ### Patch Changes - [#3330](#3330) [`dc8eb40`](dc8eb40) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - bump zod to 4.6.6 - [#3350](#3350) [`b7a4b89`](b7a4b89) Thanks [@miguelg719](https://github.com/miguelg719)! - Save run screenshots only as PNG or JPEG files, under ./stagehand-artifacts by default - Updated dependencies [[`44d99df`](44d99df), [`dc8eb40`](dc8eb40), [`edb76b0`](edb76b0), [`066e875`](066e875), [`1e50db6`](1e50db6), [`aeb1ba0`](aeb1ba0), [`18b96f2`](18b96f2), [`d59afde`](d59afde)]: - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Minor Changes - [#3325](#3325) [`d59afde`](d59afde) Thanks [@miguelg719](https://github.com/miguelg719)! - Add an extension watchdog for lost SDK clients ### Patch Changes - [#3339](#3339) [`44d99df`](44d99df) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - Adopt cross-origin iframes that were already loaded when Stagehand attached, or that are nested inside another cross-origin iframe, so snapshots and actions can reach them. - [#3330](#3330) [`dc8eb40`](dc8eb40) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - bump zod to 4.6.6 - [#3340](#3340) [`edb76b0`](edb76b0) Thanks [@akeimach](https://github.com/akeimach)! - Fix act, observe and extract with Claude Opus 5.5 by bumping `@ai-sdk/anthropic` and `ai` in the extension. - [#3387](#3387) [`066e875`](066e875) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fixed domain policy bypasses involving URLs with credentials, background requests, and speculative page loads - [#3383](#3383) [`1e50db6`](1e50db6) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - skip variable substitution for drag-and-drop arguments in act(). - [#3388](#3388) [`18b96f2`](18b96f2) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix issue where calling act() prevents cross-origin iframes from loading ## @browserbasehq/[email protected] ### Minor Changes - [#3305](#3305) [`aeb1ba0`](aeb1ba0) Thanks [@miguelg719](https://github.com/miguelg719)! - add `browser.disconnect()`, which closes an attached Stagehand instance and the connection to a browser without closing the browser or releasing its Browserbase session (Browserbase still ends sessions without `keepAlive` on disconnect). `browser.close()` after `disconnect()` now throws (connect again to close the browser), a launched local browser receives `Browser.close` before it is terminated, browser handles expose `cdpUrl` (`cdp_url` in Python) for local browsers, and `connected` reports whether the handle still has a live connection - [#3325](#3325) [`d59afde`](d59afde) Thanks [@miguelg719](https://github.com/miguelg719)! - Add an extension watchdog for lost SDK clients ### Patch Changes - [#3339](#3339) [`44d99df`](44d99df) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - Adopt cross-origin iframes that were already loaded when Stagehand attached, or that are nested inside another cross-origin iframe, so snapshots and actions can reach them. - [#3330](#3330) [`dc8eb40`](dc8eb40) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - bump zod to 4.6.6 - [#3340](#3340) [`edb76b0`](edb76b0) Thanks [@akeimach](https://github.com/akeimach)! - Fix act, observe and extract with Claude Opus 5.5 by bumping `@ai-sdk/anthropic` and `ai` in the extension. - [#3387](#3387) [`066e875`](066e875) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fixed domain policy bypasses involving URLs with credentials, background requests, and speculative page loads - [#3383](#3383) [`1e50db6`](1e50db6) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - skip variable substitution for drag-and-drop arguments in act(). - [#3388](#3388) [`18b96f2`](18b96f2) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix issue where calling act() prevents cross-origin iframes from loading ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies [[`44d99df`](44d99df), [`dc8eb40`](dc8eb40), [`edb76b0`](edb76b0), [`066e875`](066e875), [`1e50db6`](1e50db6), [`aeb1ba0`](aeb1ba0), [`18b96f2`](18b96f2), [`d59afde`](d59afde)]: - @browserbasehq/[email protected] - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies []: - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies []: - @browserbasehq/[email protected] - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies [[`44d99df`](44d99df), [`dc8eb40`](dc8eb40), [`edb76b0`](edb76b0), [`066e875`](066e875), [`1e50db6`](1e50db6), [`aeb1ba0`](aeb1ba0), [`18b96f2`](18b96f2), [`d59afde`](d59afde)]: - @browserbasehq/[email protected] - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies []: - @browserbasehq/[email protected] - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies []: - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies [[`44d99df`](44d99df), [`dc8eb40`](dc8eb40), [`edb76b0`](edb76b0), [`066e875`](066e875), [`1e50db6`](1e50db6), [`aeb1ba0`](aeb1ba0), [`18b96f2`](18b96f2), [`d59afde`](d59afde)]: - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies []: - @browserbasehq/[email protected] - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies []: - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies []: - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies []: - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies []: - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies [[`44d99df`](44d99df), [`dc8eb40`](dc8eb40), [`edb76b0`](edb76b0), [`066e875`](066e875), [`1e50db6`](1e50db6), [`aeb1ba0`](aeb1ba0), [`18b96f2`](18b96f2), [`d59afde`](d59afde)]: - @browserbasehq/[email protected] - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies []: - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies []: - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies [[`44d99df`](44d99df), [`dc8eb40`](dc8eb40), [`edb76b0`](edb76b0), [`066e875`](066e875), [`1e50db6`](1e50db6), [`aeb1ba0`](aeb1ba0), [`18b96f2`](18b96f2), [`d59afde`](d59afde)]: - @browserbasehq/[email protected] - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies []: - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies []: - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - [#3330](#3330) [`dc8eb40`](dc8eb40) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - bump zod to 4.6.6 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
why
what changed
declarativeNetRequestrulestest plan
Summary by cubic
Fixes domain policy bypasses by moving enforcement from per-page CDP Fetch interception to Chrome's
declarativeNetRequestsession rules, so blocking applies browser-wide and consistently regardless of page attachment.Bug Fixes
declarativeNetRequestextension permission; Chrome 137+ already supports the session rules API used here.Written for commit 33ea536. Summary will update on new commits.