feat(browser/cloud): connect Cloud OAuth profiles to Gateway Browser Relay

Aperta
#35 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
15/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript

Direzione di ricerca

Start with src/browser/session.ts, src/browser/transport.ts, src/shared/connect.ts, and the browser grant and policy code; read architecture issue #1354 and confirm the contract with backend issue #1451. Trace the Cloud OAuth flow and the existing gateway API-key handshake, then map the required Cloud relay path and its workspace and identity checks. Done requires the stated real staging end-to-end, isolation, renewal, security, and regression evidence; this is a large cross-cutting design and integration effort.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement security

Goal

Unblock Connected browser on Dewee Cloud for an ordinary OAuth-signed-in user of the existing Chrome Extension. No self-hosted Gateway URL or personal API key should be needed.

Backend implementation dependency: https://github.com/nextlevelbuilder/dewee/issues/1451
Architecture source of truth (design must merge first): https://github.com/nextlevelbuilder/dewee/issues/1354
Existing implementation: src/browser/session.ts currently sets mode='cloud' and stops; src/browser/transport.ts supports only gateway API-key handshake; src/shared/i18n.ts says “Connected browser is not available for Dewee Cloud yet”; src/shared/connect.ts already handles Cloud OAuth; src/browser/* already contains grant/policy/executor/tab safety. Extend existing infrastructure, do not rebuild browser control.

Agreed target design

Use Cloud OAuth → short-lived owner-bound Browser Relay credential via CCP BFF → direct WSS to the workspace's Gateway. Cloud BFF is apps/dewee-app of nextlevelbuilder/dewee, NOT the dewee-web marketing repo. Relay credentials are minted/expires/revoked by backend #1451, NOT manufactured or stored as normal API keys by extension. Do not proxy page content through CCP.

Implementation slices
  • Expand Cloud OAuth consent and token-manager to explicitly request browser scope on opt-in, with clear reauthorization/upgrade for existing Cloud sign-ins. Existing chat-only accounts must not silently gain browser grants. Reuse the single-flight refresh protection; multiple simultaneous requests must not trigger refresh replay.
  • Add typed CloudBrowserRelayClient API for versioned POST /api/extension/v1/workspaces/{workspaceId}/browser/relay-credential (and renewal/revoke if the selected contract uses dedicated routes). Parse and validate only a server-provided HTTPS/WSS runtime endpoint; reject missing/unsafe/mismatched origins, unexpected response bodies, bad TTL and changed workspace.
  • Refactor BrowserSession into independent profile auth and relay transport acquisition. gateway preserves current API-key /ws; cloud obtains temporary credential and opens same RelayTransport directly to resolved runtime wss://…/ws. Share device/grant/policy/executor, own-tab lifecycle, pause/stop, CDP opt-in, command dedupe and no-replay paths.
  • Bind relay state and device/grant cache to (Cloud profile, authenticated identity, workspace, device), not solely profile ID. On workspace switch, sign-out, OAuth family revocation, role change, or profile switch immediately disconnect, cancel commands, deny pending approvals, clear owned-tab references and invalidate temporary credentials/caches; never allow a grant from workspace A to operate in B. Preserve last user-chosen Pause/Stop across restart for the same scope (do not reset to Active by accident). A changed user must require re-enrollment/grant.
  • Request Chrome host access for the returned runtime origin from a user gesture and only from allowlisted origin (avoid <all_urls>). Retry/reconnect through token renewal when expired, with bounded jittered backoff, single-flight mint, cancellation/epoch guards and typed errors; never spin forever on 401/403/membership or feature-disabled. Chrome MV3 service-worker restart resumes only an authorized active profile; no client-side replay of a possibly executed command.
  • UX: in Cloud mode, show opt-in + workspace selector/context, Connect browser and reauthorization when necessary; use the existing device enrollment, exact-origin per-agent grant, TTL, browser.read vs browser.control, live activity, Allow once, Pause/Resume/Stop/Revoke. Display distinct actionable states for sign-in required, browser scope missing, workspace access removed, backend not enabled, permission denied, device offline, reconnecting and expired grant. Remove unconditional Cloud-not-supported notice only when eligible. English + Vietnamese accessibility/localization.
  • Maintain Standard vs Advanced build behavior (only Advanced with explicit debugger opt-in can capture screenshots). Security constraints stay intact: agent-owned tabs only, no arbitrary page script or Runtime.evaluate, restricted URLs, hidden/password/payment/OTP redaction, user takeover.
  • Docs: update README, docs/architecture.md, docs/api-contract.md, docs/connected-browser-relay-contract.md alongside backend ADR and deployment contract. Update screenshots/i18n/tests. Do not claim Telegram/Discord browser control is available: it remains blocked until backend https://github.com/nextlevelbuilder/dewee/issues/1224.

Definition of DONE (every box needs reproducible evidence)

Functional E2E, real Cloud
  • In a real staging deployment running CCP BFF + Gateway from backend #1451, a person installs Standard Chrome Extension, signs in with existing Dewee Cloud OAuth, chooses workspace, enables Connected browser, allows Chrome host permission, enrolls device, grants one agent browser.read and then browser.control on https://example.com for 15 min. Connected shows; no separate gateway setup, manual token or self-host.
  • The person's direct Cloud-authenticated conversation causes agent browser with target:"connected" to perform open → snapshot → click/type → snapshot → close on a granted test page with real outcomes and event timeline. Unapproved agent/origin is denied; no fallback to managed browser. The user can revoke access during a command and stop it.
  • A second Cloud user and a second workspace/tenant can NEVER see/control first user's device, grant or tabs; switching Cloud workspace/profile/logout while a command is in flight cancels locally and on Gateway. Login as a different Cloud user in same Chrome profile does not inherit owner bindings.
  • Cloud grants never enable control of preexisting tabs. Risky click or type-with-submit requires explicit Allow once; denied/closed side panel refuses. User typing in an agent-owned tab pauses it and requires Resume. Standard screenshot unsupported; Advanced screenshot only in opt-in build.
Renewal, resilience, security
  • Force token expiry before start, during active WSS, and during a command; verify only one mint/refresh occurs per profile/workspace at a time and affected command is never replayed. Reconnect re-attaches correctly without duplicating grants or silently re-enabling paused control. Force Chrome service worker suspend/restart and network loss; connection recovers after permission/auth restoration. Terminal membership/revocation errors stop reconnection and display correct action.
  • Temporary key and OAuth tokens do not appear in URL/query, console/debug logs, exceptions, telemetry, DOM, timeline, storage.local / storage.sync, exported diagnostics, chat transcript, or page scripts. Token is held only in protected transient memory needed for handshake and dropped on sign-out/switch. Test with sentinel tokens and storage/log snapshots.
  • Chrome permission denied, origin mismatch, runtime TLS/WSS failure, BFF 401/403/404/429/5xx, expired or revoked family, backend flag off, stale workspace and stale async response all fail closed with human-readable recovery and no profile cross-talk.
  • Existing self-hosted browser integration and Cloud chat/card/login flows fully pass unchanged; Standard and Advanced test suites pass. Add unit + integration tests around BrowserSession, transport, token-manager and grants; update live E2E (tests/e2e/live-connected-browser.spec.ts, live-cloud.spec.ts) to test actual Cloud → runtime WSS, not mock relay alone.
  • Respect outstanding security issues #33 (off-grant navigation), #25 (contenteditable redaction), #26 (iframe takeover); before general rollout, fix or provide explicit security-reviewed mitigation and negative test evidence. Publish gate is fail-closed, not assumed safe.
Release proof / closeout
  • Published extension build or reproducible sideload artifact has been tested with two separate real Cloud test accounts in staging + one unauthorized account. Record test command, suite result, at least 20 real successful browser actions, logout/revoke negative tests, redacted video/screenshots and measured reconnect/revoke latencies.
  • Final PR references backend #1451 and design #1354; backend / extension contract versions are compatible in production configuration and include rollback/feature-disable instructions. Independent security review + regression CI pass; production-like Cloud canary actually operates end-to-end, and the previous blanket “not available for Dewee Cloud” message no longer appears for eligible accounts.
  • If backend #1451 is incomplete or only mock tests pass, this issue is not DONE.

Non-goals

No broad <all_urls> install permission, no automatic access to all tabs, no generic operator.write key for Cloud, no Cloudflare WebSocket proxy, no speculative multi-channel account linking, no rewrite of the existing browser executor.

Lingua principale
TypeScript
Stelle
2
Fork
1
Merge medio
2g 5h
PR unite (30g)
4

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nextlevelbuilder/dewee-chrome-ext

Tutte le issue di nextlevelbuilder/dewee-chrome-ext

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.