Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

fix(handlers): refuse the mutating tab endpoints while a tab is paused for human handoff

Luigi Agosti6b53194e6ed1
diff --git a/internal/handlers/cookies.go b/internal/handlers/cookies.go
index c2ca833b..3c78293e 100644
--- a/internal/handlers/cookies.go
+++ b/internal/handlers/cookies.go
@@ -193,7 +193,7 @@ func (h *Handlers) HandleSetCookies(w http.ResponseWriter, r *http.Request) {
}
}
- ctx, _, ok := h.guardedTabContext(w, r, req.TabID, guardDomainPolicy)
+ ctx, _, ok := h.guardedTabContext(w, r, req.TabID, guardDomainPolicy|guardHandoffPause)
if !ok {
return
}
diff --git a/internal/handlers/credentials.go b/internal/handlers/credentials.go
index 32a7c664..81e8cf55 100644
--- a/internal/handlers/credentials.go
+++ b/internal/handlers/credentials.go
@@ -135,7 +135,7 @@ func (h *Handlers) setCredentials(w http.ResponseWriter, r *http.Request, req cr
// Non-empty username requires password field (empty password is allowed).
// Empty username means "clear credentials".
- ctx, resolvedTabID, ok := h.guardedTabContext(w, r, req.TabID, guardDomainPolicy)
+ ctx, resolvedTabID, ok := h.guardedTabContext(w, r, req.TabID, guardDomainPolicy|guardHandoffPause)
if !ok {
return
}
diff --git a/internal/handlers/download.go b/internal/handlers/download.go
index fcf34eb9..fa797d2d 100644
--- a/internal/handlers/download.go
+++ b/internal/handlers/download.go
@@ -117,7 +117,7 @@ func (h *Handlers) enforceDownloadTabPolicy(w http.ResponseWriter, r *http.Reque
httpx.ErrorCode(w, http.StatusLocked, "tab_locked", err.Error(), false, nil)
return false
}
- currentURL, ok := h.applyTabGuards(w, r, ctx, resolvedTabID, guardDomainPolicy)
+ currentURL, ok := h.applyTabGuards(w, r, ctx, resolvedTabID, guardDomainPolicy|guardHandoffPause)
if !ok {
return false
}
diff --git a/internal/handlers/geolocation.go b/internal/handlers/geolocation.go
index c3366265..9b833d72 100644
--- a/internal/handlers/geolocation.go
+++ b/internal/handlers/geolocation.go
@@ -64,7 +64,7 @@ func (h *Handlers) setGeolocation(w http.ResponseWriter, r *http.Request, req ge
req.Accuracy = 1.0
}
- ctx, resolvedTabID, ok := h.guardedTabContext(w, r, req.TabID, guardDomainPolicy)
+ ctx, resolvedTabID, ok := h.guardedTabContext(w, r, req.TabID, guardDomainPolicy|guardHandoffPause)
if !ok {
return
}
diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go
index ccb4cfe2..f64c7fbe 100644
--- a/internal/handlers/handlers.go
+++ b/internal/handlers/handlers.go
@@ -362,7 +362,7 @@ func (h *Handlers) bridgeBindings() []routeBinding {
{pattern: "GET /pdf", root: h.HandlePDF, tab: h.HandleTabPDF, guards: guardDialogBlocked | guardDomainPolicy},
{pattern: "POST /pdf", root: h.HandlePDF, tab: h.HandleTabPDF, guards: guardDialogBlocked | guardDomainPolicy},
{pattern: "POST /action", root: h.HandleAction, tab: h.HandleTabAction, guards: guardDialogBlocked | guardDomainPolicy | guardHandoffPause},
- {pattern: "POST /actions", root: h.HandleActions, tab: h.HandleTabActions, guards: guardDomainPolicy},
+ {pattern: "POST /actions", root: h.HandleActions, tab: h.HandleTabActions, guards: guardDomainPolicy}, // handoff-pause enforced PER STEP inside the batch loop, not as a request gate
{pattern: "POST /dialog", root: h.HandleDialog, tab: h.HandleTabDialog, guards: guardHandoffPause},
{pattern: "POST /wait", root: h.HandleWait, tab: h.HandleTabWait, guards: guardDomainPolicy},
{pattern: "POST /find", root: h.HandleFind, tab: h.HandleFind, guards: guardDomainPolicy},
@@ -373,8 +373,8 @@ func (h *Handlers) bridgeBindings() []routeBinding {
{pattern: "POST /handoff", tab: h.HandleTabHandoff, tabOnly: true, guards: guardDomainPolicy},
{pattern: "POST /resume", tab: h.HandleTabResume, tabOnly: true, guards: guardDomainPolicy},
{pattern: "GET /handoff", tab: h.HandleTabHandoffStatus, tabOnly: true, guards: guardNone},
- {pattern: "GET /cookies", root: h.HandleGetCookies, tab: h.HandleTabGetCookies, guards: guardDomainPolicy},
- {pattern: "POST /cookies", root: h.HandleSetCookies, tab: h.HandleTabSetCookies, guards: guardDomainPolicy},
+ {pattern: "GET /cookies", root: h.HandleGetCookies, tab: h.HandleTabGetCookies, guards: guardDomainPolicy}, // no handoff-pause: reads the tab's cookies, changes nothing the human sees
+ {pattern: "POST /cookies", root: h.HandleSetCookies, tab: h.HandleTabSetCookies, guards: guardDomainPolicy | guardHandoffPause},
{pattern: "DELETE /cookies", root: h.HandleClearCookies, tab: h.HandleTabClearCookies, guards: guardNone},
{pattern: "GET /metrics", root: h.HandleMetrics, tab: h.HandleTabMetrics, guards: guardNone},
{pattern: "GET /timing", root: h.HandleTiming, tab: h.HandleTabTiming, guards: guardDialogBlocked | guardDomainPolicy},
@@ -382,15 +382,15 @@ func (h *Handlers) bridgeBindings() []routeBinding {
{pattern: "POST /audit/page", root: h.HandleAuditPage, guards: guardNone},
{pattern: "POST /audit", root: h.HandleAudit, guards: guardNone},
{pattern: "POST /scrape", root: h.HandleScrape, guards: guardNone},
- {pattern: "GET /network", root: h.HandleNetwork, tab: h.HandleTabNetwork, guards: guardDomainPolicy},
- {pattern: "GET /network/stream", root: h.HandleNetworkStream, tab: h.HandleTabNetworkStream, guards: guardDomainPolicy},
- {pattern: "GET /network/export", root: h.HandleNetworkExport, tab: h.HandleTabNetworkExport, guards: guardDomainPolicy},
- {pattern: "GET /network/export/stream", root: h.HandleNetworkExportStream, tab: h.HandleTabNetworkExportStream, guards: guardDomainPolicy},
- {pattern: "GET /network/{requestId}", root: h.HandleNetworkByID, tab: h.HandleTabNetworkByID, guards: guardDomainPolicy},
+ {pattern: "GET /network", root: h.HandleNetwork, tab: h.HandleTabNetwork, guards: guardDomainPolicy}, // no handoff-pause: the /network reads serve the capture buffer, never the page
+ {pattern: "GET /network/stream", root: h.HandleNetworkStream, tab: h.HandleTabNetworkStream, guards: guardDomainPolicy}, // no handoff-pause: read probe
+ {pattern: "GET /network/export", root: h.HandleNetworkExport, tab: h.HandleTabNetworkExport, guards: guardDomainPolicy}, // no handoff-pause: read probe
+ {pattern: "GET /network/export/stream", root: h.HandleNetworkExportStream, tab: h.HandleTabNetworkExportStream, guards: guardDomainPolicy}, // no handoff-pause: read probe
+ {pattern: "GET /network/{requestId}", root: h.HandleNetworkByID, tab: h.HandleTabNetworkByID, guards: guardDomainPolicy}, // no handoff-pause: read probe
{pattern: "POST /network/clear", root: h.HandleNetworkClear, guards: guardNone},
{pattern: "GET /network/route", root: h.HandleNetworkRouteList, tab: h.HandleTabNetworkRouteList, guards: guardNone},
- {pattern: "POST /network/route", root: h.HandleNetworkRoute, tab: h.HandleTabNetworkRoute, guards: guardDomainPolicy},
- {pattern: "DELETE /network/route", root: h.HandleNetworkUnroute, tab: h.HandleTabNetworkUnroute, guards: guardDomainPolicy},
+ {pattern: "POST /network/route", root: h.HandleNetworkRoute, tab: h.HandleTabNetworkRoute, guards: guardDomainPolicy | guardHandoffPause},
+ {pattern: "DELETE /network/route", root: h.HandleNetworkUnroute, tab: h.HandleTabNetworkUnroute, guards: guardDomainPolicy | guardHandoffPause},
{pattern: "GET /console", root: h.HandleGetConsoleLogs, guards: guardDomainPolicy},
{pattern: "POST /console/clear", root: h.HandleClearConsoleLogs, guards: guardNone},
{pattern: "GET /errors", root: h.HandleGetErrorLogs, guards: guardDomainPolicy},
@@ -400,32 +400,32 @@ func (h *Handlers) bridgeBindings() []routeBinding {
{pattern: "POST /clipboard/copy", root: h.HandleClipboardCopy, guards: guardNone},
{pattern: "GET /clipboard/paste", root: h.HandleClipboardPaste, guards: guardNone},
{pattern: "GET /stealth/status", root: h.HandleStealthStatus, guards: guardNone},
- {pattern: "POST /fingerprint/rotate", root: h.HandleFingerprintRotate, guards: guardDomainPolicy},
+ {pattern: "POST /fingerprint/rotate", root: h.HandleFingerprintRotate, guards: guardDomainPolicy | guardHandoffPause},
{pattern: "GET /solvers", root: h.HandleListSolvers, guards: guardNone},
{pattern: "GET /config/autosolver", root: h.HandleAutoSolverConfig, guards: guardNone},
{pattern: "POST /solve", root: h.HandleSolve, tab: h.HandleTabSolve, guards: guardDomainPolicy | guardHandoffPause},
{pattern: "POST /solve/{name}", root: h.HandleSolve, tab: h.HandleTabSolve, guards: guardDomainPolicy | guardHandoffPause},
- {pattern: "POST /emulation/viewport", root: h.HandleSetViewport, tab: h.HandleTabSetViewport, guards: guardDomainPolicy},
- {pattern: "POST /emulation/geolocation", root: h.HandleSetGeolocation, tab: h.HandleTabSetGeolocation, guards: guardDomainPolicy},
- {pattern: "POST /emulation/offline", root: h.HandleSetOffline, tab: h.HandleTabSetOffline, guards: guardDomainPolicy},
- {pattern: "POST /emulation/headers", root: h.HandleSetHeaders, tab: h.HandleTabSetHeaders, guards: guardDomainPolicy},
- {pattern: "POST /emulation/credentials", root: h.HandleSetCredentials, tab: h.HandleTabSetCredentials, guards: guardDomainPolicy},
- {pattern: "POST /emulation/media", root: h.HandleSetMedia, tab: h.HandleTabSetMedia, guards: guardDomainPolicy},
+ {pattern: "POST /emulation/viewport", root: h.HandleSetViewport, tab: h.HandleTabSetViewport, guards: guardDomainPolicy | guardHandoffPause},
+ {pattern: "POST /emulation/geolocation", root: h.HandleSetGeolocation, tab: h.HandleTabSetGeolocation, guards: guardDomainPolicy | guardHandoffPause},
+ {pattern: "POST /emulation/offline", root: h.HandleSetOffline, tab: h.HandleTabSetOffline, guards: guardDomainPolicy | guardHandoffPause},
+ {pattern: "POST /emulation/headers", root: h.HandleSetHeaders, tab: h.HandleTabSetHeaders, guards: guardDomainPolicy | guardHandoffPause},
+ {pattern: "POST /emulation/credentials", root: h.HandleSetCredentials, tab: h.HandleTabSetCredentials, guards: guardDomainPolicy | guardHandoffPause},
+ {pattern: "POST /emulation/media", root: h.HandleSetMedia, tab: h.HandleTabSetMedia, guards: guardDomainPolicy | guardHandoffPause},
{pattern: "POST /cache/clear", root: h.HandleCacheClear, guards: guardNone},
{pattern: "GET /cache/status", root: h.HandleCacheStatus, guards: guardNone},
- {pattern: "POST /storage", root: h.HandleStorage, tab: h.HandleTabStorageSet, guards: guardDomainPolicy},
- {pattern: "DELETE /storage", root: h.HandleStorage, tab: h.HandleTabStorageDelete, guards: guardDomainPolicy},
- {pattern: "GET /storage", root: h.HandleStorage, tab: h.HandleTabStorageGet, guards: guardDomainPolicy},
- {pattern: "GET /state", root: h.HandleStateCurrent, guards: guardDomainPolicy},
+ {pattern: "POST /storage", root: h.HandleStorage, tab: h.HandleTabStorageSet, guards: guardDomainPolicy | guardHandoffPause},
+ {pattern: "DELETE /storage", root: h.HandleStorage, tab: h.HandleTabStorageDelete, guards: guardDomainPolicy | guardHandoffPause},
+ {pattern: "GET /storage", root: h.HandleStorage, tab: h.HandleTabStorageGet, guards: guardDomainPolicy}, // no handoff-pause: read probe; the POST/DELETE siblings carry it
+ {pattern: "GET /state", root: h.HandleStateCurrent, guards: guardDomainPolicy}, // no handoff-pause: captures a snapshot, writes nothing to the tab
{pattern: "GET /state/list", root: h.HandleStateList, guards: guardNone},
{pattern: "GET /state/show", root: h.HandleStateShow, guards: guardNone},
- {pattern: "POST /state/save", root: h.HandleStateSave, guards: guardDomainPolicy},
- {pattern: "POST /state/load", root: h.HandleStateLoad, guards: guardDomainPolicy},
+ {pattern: "POST /state/save", root: h.HandleStateSave, guards: guardDomainPolicy}, // no handoff-pause: POST writes a file, not the tab; /state/load is the write and carries it
+ {pattern: "POST /state/load", root: h.HandleStateLoad, guards: guardDomainPolicy | guardHandoffPause},
{pattern: "DELETE /state", root: h.HandleStateDelete, guards: guardNone},
{pattern: "POST /state/clean", root: h.HandleStateClean, guards: guardNone},
{pattern: "POST /evaluate", root: h.HandleEvaluate, tab: h.HandleTabEvaluate, guards: guardDomainPolicy | guardHandoffPause},
- {pattern: "POST /macro", root: h.HandleMacro, guards: guardDomainPolicy},
- {pattern: "GET /download", root: h.HandleDownload, tab: h.HandleTabDownload, guards: guardDomainPolicy},
+ {pattern: "POST /macro", root: h.HandleMacro, guards: guardDomainPolicy}, // handoff-pause enforced PER STEP inside the macro loop, not as a request gate
+ {pattern: "GET /download", root: h.HandleDownload, tab: h.HandleTabDownload, guards: guardDomainPolicy | guardHandoffPause},
{pattern: "POST /upload", root: h.HandleUpload, tab: h.HandleTabUpload, guards: guardDomainPolicy | guardHandoffPause},
{pattern: "GET /screencast", root: h.HandleScreencast, guards: guardDomainPolicy},
{pattern: "GET /screencast/tabs", root: h.HandleScreencastAll, guards: guardNone},
diff --git a/internal/handlers/headers.go b/internal/handlers/headers.go
index 8099a8db..f419d9c4 100644
--- a/internal/handlers/headers.go
+++ b/internal/handlers/headers.go
@@ -48,7 +48,7 @@ func (h *Handlers) setHeaders(w http.ResponseWriter, r *http.Request, req header
return
}
- ctx, resolvedTabID, ok := h.guardedTabContext(w, r, req.TabID, guardDomainPolicy)
+ ctx, resolvedTabID, ok := h.guardedTabContext(w, r, req.TabID, guardDomainPolicy|guardHandoffPause)
if !ok {
return
}
diff --git a/internal/handlers/media.go b/internal/handlers/media.go
index 24cc71b2..818ada1b 100644
--- a/internal/handlers/media.go
+++ b/internal/handlers/media.go
@@ -53,7 +53,7 @@ func (h *Handlers) setMedia(w http.ResponseWriter, r *http.Request, req mediaReq
return
}
- ctx, resolvedTabID, ok := h.guardedTabContext(w, r, req.TabID, guardDomainPolicy)
+ ctx, resolvedTabID, ok := h.guardedTabContext(w, r, req.TabID, guardDomainPolicy|guardHandoffPause)
if !ok {
return
}
diff --git a/internal/handlers/network_route.go b/internal/handlers/network_route.go
index e6db348b..c4ab952c 100644
--- a/internal/handlers/network_route.go
+++ b/internal/handlers/network_route.go
@@ -125,7 +125,7 @@ func (h *Handlers) handleNetworkRouteFor(w http.ResponseWriter, r *http.Request,
if !ok {
return
}
- if _, ok := h.applyTabGuards(w, r, tabCtx, resolvedID, guardDomainPolicy); !ok {
+ if _, ok := h.applyTabGuards(w, r, tabCtx, resolvedID, guardDomainPolicy|guardHandoffPause); !ok {
return
}
@@ -187,7 +187,7 @@ func (h *Handlers) handleNetworkUnrouteFor(w http.ResponseWriter, r *http.Reques
if !ok {
return
}
- if _, ok := h.applyTabGuards(w, r, tabCtx, resolvedID, guardDomainPolicy); !ok {
+ if _, ok := h.applyTabGuards(w, r, tabCtx, resolvedID, guardDomainPolicy|guardHandoffPause); !ok {
return
}
diff --git a/internal/handlers/offline.go b/internal/handlers/offline.go
index d190732d..25ff0e8a 100644
--- a/internal/handlers/offline.go
+++ b/internal/handlers/offline.go
@@ -55,7 +55,7 @@ func (h *Handlers) setOffline(w http.ResponseWriter, r *http.Request, req offlin
req.UploadThroughput = -1
}
- ctx, resolvedTabID, ok := h.guardedTabContext(w, r, req.TabID, guardDomainPolicy)
+ ctx, resolvedTabID, ok := h.guardedTabContext(w, r, req.TabID, guardDomainPolicy|guardHandoffPause)
if !ok {
return
}
diff --git a/internal/handlers/state_capture.go b/internal/handlers/state_capture.go
index 272e317f..734125dd 100644
--- a/internal/handlers/state_capture.go
+++ b/internal/handlers/state_capture.go
@@ -93,7 +93,7 @@ func (h *Handlers) HandleStateLoad(w http.ResponseWriter, r *http.Request) {
return
}
- ctx, resolvedTabID, ok := h.guardedTabContext(w, r, req.TabID, guardDomainPolicy)
+ ctx, resolvedTabID, ok := h.guardedTabContext(w, r, req.TabID, guardDomainPolicy|guardHandoffPause)
if !ok {
return
}
diff --git a/internal/handlers/stealth.go b/internal/handlers/stealth.go
index 3a302659..a621577b 100644
--- a/internal/handlers/stealth.go
+++ b/internal/handlers/stealth.go
@@ -36,7 +36,7 @@ func (h *Handlers) HandleFingerprintRotate(w http.ResponseWriter, r *http.Reques
return
}
- ctx, resolvedTabID, ok := h.guardedTabContext(w, r, req.TabID, guardDomainPolicy)
+ ctx, resolvedTabID, ok := h.guardedTabContext(w, r, req.TabID, guardDomainPolicy|guardHandoffPause)
if !ok {
return
}
diff --git a/internal/handlers/storage.go b/internal/handlers/storage.go
index 6d6ea77d..72408ac2 100644
--- a/internal/handlers/storage.go
+++ b/internal/handlers/storage.go
@@ -45,9 +45,11 @@ func (h *Handlers) ensureStateExportEnabled(w http.ResponseWriter) bool {
// timeout, decodes the JSON result, records activity + logs, and writes the
// response. It writes any error response and returns. opLabel is the error/log
// infix ("get"/"set"/"delete"); activityAction is the recordActivity action;
-// logType/logKey are the structured-log values.
-func (h *Handlers) runStorageOp(w http.ResponseWriter, r *http.Request, tabID, script, opLabel, activityAction, logType, logKey string) {
- ctx, resolvedTabID, ok := h.guardedTabContext(w, r, tabID, guardDomainPolicy)
+// logType/logKey are the structured-log values. guards comes from the caller
+// because the three ops share this body but not their guard set: the writes
+// carry handoff-pause, the read does not.
+func (h *Handlers) runStorageOp(w http.ResponseWriter, r *http.Request, tabID, script, opLabel, activityAction, logType, logKey string, guards tabGuards) {
+ ctx, resolvedTabID, ok := h.guardedTabContext(w, r, tabID, guards)
if !ok {
return
}
@@ -94,7 +96,7 @@ func (h *Handlers) handleStorageGet(w http.ResponseWriter, r *http.Request) {
key := r.URL.Query().Get("key")
script := buildStorageGetScript(storageType, key)
- h.runStorageOp(w, r, tabID, script, "get", "storage.read", storageType, key)
+ h.runStorageOp(w, r, tabID, script, "get", "storage.read", storageType, key, guardDomainPolicy)
}
type storageSetRequest struct {
@@ -145,7 +147,7 @@ func (h *Handlers) handleStorageSet(w http.ResponseWriter, r *http.Request) {
}
`, storageObj, string(keyJSON), string(valueJSON))
- h.runStorageOp(w, r, req.TabID, script, "set", "storage.write", req.Type, req.Key)
+ h.runStorageOp(w, r, req.TabID, script, "set", "storage.write", req.Type, req.Key, guardDomainPolicy|guardHandoffPause)
}
// handleStorageDelete removes a storage item or clears storage.
@@ -189,7 +191,7 @@ func (h *Handlers) handleStorageDelete(w http.ResponseWriter, r *http.Request) {
}
script := buildStorageDeleteScript(req.Type, req.Key)
- h.runStorageOp(w, r, req.TabID, script, "delete", "storage.delete", req.Type, req.Key)
+ h.runStorageOp(w, r, req.TabID, script, "delete", "storage.delete", req.Type, req.Key, guardDomainPolicy|guardHandoffPause)
}
// buildStorageGetScript builds a JS expression that reads from localStorage
diff --git a/internal/handlers/tab_guards_test.go b/internal/handlers/tab_guards_test.go
index df608389..dc7c84c2 100644
--- a/internal/handlers/tab_guards_test.go
+++ b/internal/handlers/tab_guards_test.go
@@ -47,6 +47,11 @@ type guardProbeBridge struct {
dialogs *bridge.DialogManager
}
+// probePausedAt is fixed so two refusals from different endpoints differ only
+// where they are genuinely allowed to; a live clock would put a different
+// pausedAt in each body and make the envelope comparison below untestable.
+var probePausedAt = time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)
+
func pendingDialogManager() *bridge.DialogManager {
dm := bridge.NewDialogManager()
dm.SetPending("tab1", &bridge.DialogState{Type: "confirm", Message: "probe"})
@@ -61,12 +66,11 @@ func (b *guardProbeBridge) TabHandoffState(string) (bridge.TabHandoffState, bool
if !b.paused {
return bridge.TabHandoffState{Status: "active"}, true
}
- now := time.Now().UTC()
return bridge.TabHandoffState{
Status: "paused_handoff",
Reason: "manual_handoff",
- PausedAt: now,
- LastUpdatedAt: now,
+ PausedAt: probePausedAt,
+ LastUpdatedAt: probePausedAt,
}, true
}
@@ -159,6 +163,16 @@ func allCapabilities(t *testing.T, tmpDir string) *config.RuntimeConfig {
// way.
func probeRoute(t *testing.T, b bridge.BridgeAPI, cfg *config.RuntimeConfig, ep routes.Endpoint) (code string, status int, answered bool) {
t.Helper()
+ w, answered := recordProbeRoute(t, b, cfg, ep)
+ var resp struct {
+ Code string `json:"code"`
+ }
+ _ = json.Unmarshal(w.Body.Bytes(), &resp)
+ return resp.Code, w.Code, answered
+}
+
+func recordProbeRoute(t *testing.T, b bridge.BridgeAPI, cfg *config.RuntimeConfig, ep routes.Endpoint) (*httptest.ResponseRecorder, bool) {
+ t.Helper()
h := New(b, cfg, nil, nil, nil)
mux := http.NewServeMux()
@@ -180,7 +194,7 @@ func probeRoute(t *testing.T, b bridge.BridgeAPI, cfg *config.RuntimeConfig, ep
}
w := httptest.NewRecorder()
- answered = true
+ answered := true
done := make(chan struct{})
go func() {
defer close(done)
@@ -203,11 +217,7 @@ func probeRoute(t *testing.T, b bridge.BridgeAPI, cfg *config.RuntimeConfig, ep
t.Fatalf("%s did not answer within the deadline", route)
}
- var resp struct {
- Code string `json:"code"`
- }
- _ = json.Unmarshal(w.Body.Bytes(), &resp)
- return resp.Code, w.Code, answered
+ return w, answered
}
// guardedBindings pairs every catalog endpoint with the binding that declares
@@ -336,3 +346,140 @@ func TestDeclaredDialogGuardMatchesTheRefusal(t *testing.T) {
t.Fatalf("checked %d routes and saw %d dialog refusals; with none observed this test cannot tell a guard from its absence", checked, refusals)
}
}
+
+// newlyGuardedMutators are the endpoints the mutating-tab ruling moved onto the
+// handoff-pause guard. Kept as an explicit list rather than derived from the
+// catalog so the ruling itself is reviewable here: a route leaving this list
+// is a policy decision someone has to delete a line to make.
+var newlyGuardedMutators = []string{
+ "POST /emulation/viewport",
+ "POST /emulation/geolocation",
+ "POST /emulation/offline",
+ "POST /emulation/headers",
+ "POST /emulation/credentials",
+ "POST /emulation/media",
+ "POST /cookies",
+ "POST /storage",
+ "DELETE /storage",
+ "POST /fingerprint/rotate",
+ "POST /network/route",
+ "DELETE /network/route",
+ "POST /state/load",
+ "GET /download",
+}
+
+// handoffRefusalReference is an endpoint that carried the handoff-pause guard
+// before the ruling, so every newly-guarded endpoint can be compared against a
+// refusal the product already shipped rather than against a literal restated in
+// this file.
+const handoffRefusalReference = "POST /evaluate"
+
+func endpointByRoute(t *testing.T, route string) routes.Endpoint {
+ t.Helper()
+ for _, ep := range routes.Core() {
+ if ep.Route() == route {
+ return ep
+ }
+ }
+ t.Fatalf("no catalog endpoint for %q", route)
+ return routes.Endpoint{}
+}
+
+// TestNewlyGuardedMutatorsRefuseAPausedTabIdentically is the ruling's evidence:
+// each endpoint moved onto the guard answers a paused tab with byte-identical
+// status and body to an endpoint that was already guarded. Comparing whole
+// envelopes rather than just the code is what makes "same error shape" a claim
+// the test can actually break on — a divergent hint, remedy or status fails.
+func TestNewlyGuardedMutatorsRefuseAPausedTabIdentically(t *testing.T) {
+ paused := func() *guardProbeBridge {
+ return &guardProbeBridge{paused: true, currentURL: "https://allowed.example/"}
+ }
+
+ refW, _ := recordProbeRoute(t, paused(), allCapabilities(t, t.TempDir()), endpointByRoute(t, handoffRefusalReference))
+ assertHandoffRefusal(t, refW)
+ wantStatus, wantBody := refW.Code, refW.Body.String()
+
+ for _, route := range newlyGuardedMutators {
+ t.Run(route, func(t *testing.T) {
+ w, _ := recordProbeRoute(t, paused(), allCapabilities(t, t.TempDir()), endpointByRoute(t, route))
+
+ assertHandoffRefusal(t, w)
+ if w.Code != wantStatus || w.Body.String() != wantBody {
+ t.Fatalf("refusal differs from %s\n got %d %s\nwant %d %s",
+ handoffRefusalReference, w.Code, w.Body.String(), wantStatus, wantBody)
+ }
+ })
+ }
+
+ if len(newlyGuardedMutators) == 0 {
+ t.Fatal("the ruled list is empty, so this test proves nothing")
+ }
+}
+
+// TestReadProbesInRuledFamiliesStayUnguarded is the other half of the ruling:
+// the read-only siblings inside the families it names keep serving a paused tab.
+// Without it, widening a shared helper's guard set would silently block reads
+// and nothing would notice.
+func TestReadProbesInRuledFamiliesStayUnguarded(t *testing.T) {
+ readProbes := []string{
+ "GET /cookies",
+ "GET /storage",
+ "GET /state",
+ "POST /state/save",
+ "GET /network",
+ "GET /network/stream",
+ "GET /network/export",
+ "GET /network/{requestId}",
+ }
+
+ for _, route := range readProbes {
+ t.Run(route, func(t *testing.T) {
+ b := &guardProbeBridge{paused: true, currentURL: "https://allowed.example/"}
+ code, status, _ := probeRoute(t, b, allCapabilities(t, t.TempDir()), endpointByRoute(t, route))
+
+ if code == handoffPausedCode {
+ t.Fatalf("read probe now refuses a paused tab (%d %s); the ruling exempts reads and the catalog line says so", status, code)
+ }
+ })
+ }
+}
+
+// TestRootStorageMethodDispatchSplitsTheGuard covers the one place this ruling
+// could not express itself as a catalog line alone: GET, POST and DELETE
+// /storage are three declarations served by one root handler over one shared
+// body, so the guard set has to travel with the operation. The reads must still
+// serve a paused tab while the writes refuse it — a widened shared helper would
+// silently block reads and every per-route probe above would still pass, since
+// they drive the tab form.
+func TestRootStorageMethodDispatchSplitsTheGuard(t *testing.T) {
+ cases := []struct {
+ method string
+ body string
+ wantRefuse bool
+ }{
+ {http.MethodGet, "", false},
+ {http.MethodPost, `{"type":"local","key":"probe","value":"1"}`, true},
+ {http.MethodDelete, `{"type":"local","key":"probe"}`, true},
+ }
+
+ for _, tc := range cases {
+ t.Run(tc.method, func(t *testing.T) {
+ h := New(&guardProbeBridge{paused: true, currentURL: "https://allowed.example/"}, allCapabilities(t, t.TempDir()), nil, nil, nil)
+
+ req := httptest.NewRequest(tc.method, "/storage?tabId=tab1&type=local&key=probe", strings.NewReader(tc.body))
+ req.Header.Set("Content-Type", "application/json")
+ w := httptest.NewRecorder()
+ h.HandleStorage(w, req)
+
+ var resp struct {
+ Code string `json:"code"`
+ }
+ _ = json.Unmarshal(w.Body.Bytes(), &resp)
+ refused := resp.Code == handoffPausedCode
+
+ if refused != tc.wantRefuse {
+ t.Fatalf("%s /storage on a paused tab: refused=%v want %v (%d %s)", tc.method, refused, tc.wantRefuse, w.Code, w.Body.String())
+ }
+ })
+ }
+}
diff --git a/internal/handlers/viewport.go b/internal/handlers/viewport.go
index ac71a808..939784a3 100644
--- a/internal/handlers/viewport.go
+++ b/internal/handlers/viewport.go
@@ -56,7 +56,7 @@ func (h *Handlers) setViewport(w http.ResponseWriter, r *http.Request, req viewp
req.DeviceScaleFactor = 1.0
}
- ctx, resolvedTabID, ok := h.guardedTabContext(w, r, req.TabID, guardDomainPolicy)
+ ctx, resolvedTabID, ok := h.guardedTabContext(w, r, req.TabID, guardDomainPolicy|guardHandoffPause)
if !ok {
return
}
diff --git a/tests/e2e/scenarios/api/tabs-extended.sh b/tests/e2e/scenarios/api/tabs-extended.sh
index b93c2b12..2fb4abe0 100644
--- a/tests/e2e/scenarios/api/tabs-extended.sh
+++ b/tests/e2e/scenarios/api/tabs-extended.sh
@@ -369,6 +369,20 @@ pt_post /action -d "{\"kind\":\"click\",\"selector\":\"#increment\",\"tabId\":\"
assert_http_status 409 "action blocked during handoff"
assert_contains "$RESULT" "tab_paused_handoff" "error code is tab_paused_handoff"
+# Mutating emulation endpoints answer the same refusal: an agent must not resize
+# or relocate a tab a human is mid-handoff on.
+pt_post "/tabs/${BLOCK_TAB}/emulation/viewport" -d '{"width":640,"height":480}'
+assert_http_status 409 "viewport blocked during handoff"
+assert_contains "$RESULT" "tab_paused_handoff" "viewport refusal carries tab_paused_handoff"
+
+pt_post "/tabs/${BLOCK_TAB}/emulation/geolocation" -d '{"latitude":1,"longitude":2}'
+assert_http_status 409 "geolocation blocked during handoff"
+
+# Reads stay available: the ruling exempts probes so an operator can still see
+# what the paused tab is doing.
+pt_get "/tabs/${BLOCK_TAB}/storage?type=local"
+assert_ok "storage read still served during handoff"
+
pt_post "/tabs/${BLOCK_TAB}/resume" -d '{}'
assert_ok "resume tab"