Skip to content

[fix]: harden domain policy setting - #3387

Merged
seanmcguire12 merged 5 commits into
mainfrom
harden-domain-policy-url-matching
Nov 4, 2026
Merged

seanmcguire12 merged 5 commits into
mainfrom
harden-domain-policy-url-matching

Conversation

@seanmcguire12

@seanmcguire12 seanmcguire12 commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

why

  • domain enforcement should apply consistently across browser activity, independent of page attachment

what changed

  • moved domain enforcement to Chrome’s declarativeNetRequest rules
  • removed domain-specific Fetch interception
  • hardened URL matching to preserve domain boundaries across supported URL formats.

test plan

  • added integration tests for URL matching, redirects, background requests, speculative loads, iframe requests, and runtime policy updates and clearing

Summary by cubic

Fixes domain policy bypasses by moving enforcement from per-page CDP Fetch interception to Chrome's declarativeNetRequest session rules, so blocking applies browser-wide and consistently regardless of page attachment.

Bug Fixes

  • Covers credentialed URLs, trailing dots, ports, worker requests, cross-site iframes, Background Fetch, prefetch/prerender speculation, redirects, and form-driven navigations.
  • Clears policy rules when a Stagehand instance is disposed so a retained browser session never carries stale policy, with retryable cleanup if Chrome rejects rule removal.
  • Adds the declarativeNetRequest extension permission; Chrome 137+ already supports the session rules API used here.

Written for commit 33ea536. Summary will update on new commits.

View guided diff Turn on auto-fix

@changeset-bot

changeset-bot Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 33ea536

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 23 packages
Name Type
@browserbasehq/stagehand-extension Patch
@browserbasehq/stagehand Patch
@browserbasehq/stagehand-python Patch
browse Patch
@browserbasehq/stagehand-examples Patch
@browserbasehq/stagehand-integrations-claude-cua-sdk Patch
@browserbasehq/stagehand-integrations Patch
@browserbasehq/eve Patch
@browserbasehq/stagehand-integrations-gemini-cua-sdk Patch
@browserbasehq/stagehand-integrations-example-pi-facade Patch
@browserbasehq/stagehand-integrations-claude-agent-sdk Patch
@browserbasehq/stagehand-integrations-example-claude-code-facade Patch
@browserbasehq/stagehand-integrations-codex-sdk Patch
@browserbasehq/stagehand-integrations-example-codex-facade Patch
@browserbasehq/stagehand-integrations-cursor-sdk Patch
@browserbasehq/stagehand-integrations-example-cursor-facade Patch
@browserbasehq/stagehand-integrations-deepagents-sdk Patch
@browserbasehq/stagehand-integrations-eve-sdk Patch
@browserbasehq/stagehand-integrations-fx-sdk Patch
@browserbasehq/stagehand-integrations-mastra-sdk Patch
@browserbasehq/stagehand-integrations-example-mastra-facade Patch
@browserbasehq/stagehand-integrations-pi-sdk Patch
@browserbasehq/stagehand-integrations-example-vercel-ai-facade Patch

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

@cubic-dev-ai cubic-dev-ai 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.

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
Loading

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread packages/extension/runtime.ts Resolved
@seanmcguire12
seanmcguire12 added this pull request to stack #3389 November 4, 2026 03:19

@cubic-dev-ai cubic-dev-ai 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.

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
Loading

View guided diff | Turn on auto-fix | Re-trigger cubic

@seanmcguire12
seanmcguire12 merged commit 066e875 into main Nov 4, 2026
60 checks passed
@seanmcguire12
seanmcguire12 deleted the harden-domain-policy-url-matching branch November 4, 2026 05:09
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants