Skip to content

Check a session's browser grants when it's created - #115

Open
samuelcole wants to merge 4 commits into
mainfrom
sam/hbr-159-session-browser-grant
Open

samuelcole wants to merge 4 commits into
mainfrom
sam/hbr-159-session-browser-grant

Conversation

@samuelcole

@samuelcole samuelcole commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes HBR-159

Problem

When a page created a session with browser access (agent.sessions.create({ capabilities: { browser: [...] } }), or agent.requestCapabilities() with a browser.* action), page-api/handlers/session-handlers.ts checked only the model and tool grants. Harbor's session.create gate then ran the browser checks with upstreamConsent: 'origin-grant', telling the policy engine the page API had already checked the grant, which it hadn't. With no grant stored, the check passed and the audit log recorded consent: "origin-grant".

So a session could report browser access the site didn't hold, and the Activity feed said the site's grant allowed it. It wasn't a way around a grant: each browser call checks its own grant. But the session and the audit were wrong.

Change

  • handleSessionsCreate now requires the matching grant for each browser capability (read → browser:activeTab.read, interact → browser:activeTab.interact, screenshot → browser:activeTab.screenshot, the same mapping live sessions use). A missing grant refuses with ERR_PERMISSION_DENIED before Harbor's session.create runs, so the gate's "origin grant already checked" is now true. Optional browser capabilities are still left out quietly by requestCapabilities().
  • Screenshots (found in review). requestCapabilities() asked for read access along with any screenshot, so with the new check a site holding only the screenshot grant couldn't get a screenshot session. A screenshot now asks only for screenshot access, the one grant a screenshot call checks.
  • The test mock (spec/testing/harness-template/mock.js) requires browser grants the same way and uses the same screenshot mapping. Its docs no longer list that as a difference from Harbor.
  • Docs. docs/PERMISSIONS.md, docs/TESTING_YOUR_APP.md, the harness README and the changelog.

Testing

  • Red first: 60509ae (a browser session without its grant is refused and never reaches Harbor's session.create; the harness example), then f63a6b6 for screenshots (request-capabilities-optional.test.ts, example.capabilities.test.mjs).
  • npx vitest run: 144 files, 1612 tests pass. Harness examples: 26 pass.
  • npm run build and npm run build:chrome succeed. tsc has the same errors as the base.
  • Firefox browser tests (tests/e2e): 21/21 pass.
  • Nothing in demo/ or tests/e2e/ creates sessions with browser access, so nothing there changes behaviour.
  • An independent review of the first version found the screenshot regression and a stale comment, both fixed here. I reviewed that small follow-up myself rather than sending it back out.

Process note

While building, the worker briefly ran git stash and git commit --amend, both against this repo's rules. It caught both before anything was pushed. The stash was popped and confirmed empty, and the final commits are correct. Nothing was lost or rewritten on the remote.

This PR was opened by an AI agent (Claude Code) working for the maintainer.

🤖 Generated with Claude Code

samuelcole and others added 4 commits November 23, 2026 13:49
… its grant at creation

handleSessionsCreate checks model:prompt and mcp:tools.call before
creating a session, but not the matching browser:activeTab.* grant for
a requested browser capability, so a session can report browser access
the origin never granted. These tests, and the mock's matching case,
are red against today's code; the fix follows in a separate commit.
…(HBR-159)

handleSessionsCreate checked only model:prompt and mcp:tools.call before
creating a session, so a requested browser capability (agent.sessions.create
or the browser.* actions requestCapabilities() builds from) sailed through
with no grant check. Harbor's session.create page gate then ran its browser
checks with upstreamConsent: 'origin-grant', trusting that the page API had
already checked the grant — which it hadn't. With no stored grant the check
passed at Tier 9 and the audit recorded the site's grant as having allowed
it, though the site held none.

handleSessionsCreate now requires the matching browser:activeTab.* grant for
each requested browser capability, the same way it already requires
model:prompt and mcp:tools.call, refusing with ERR_PERMISSION_DENIED when
it's missing. Each browser call still checks its own grant again when it's
made. The generated test harness's mock matches this, and docs/PERMISSIONS.md,
docs/TESTING_YOUR_APP.md and the harness README no longer describe the gap.

Co-Authored-By: Claude Sonnet 5 (Claude Code) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (Claude Code) <noreply@anthropic.com>
requestCapabilities (and the test mock) turned browser.read.screenshot
into both read and screenshot access, needing both grants. A screenshot
call checks only browser:activeTab.screenshot, and now that session
creation checks browser grants, a site holding just that grant couldn't
get a screenshot session. A screenshot now asks only for screenshot
access. Also updates requestCapabilities' comment: session creation now
checks browser grants too.

Co-Authored-By: Claude Opus 5.5 (Claude Code) <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant