Skip to content

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

Restrict /evaluate endpoint via PINCHTAB_ALLOW_EVALUATE

Roopesh13cf96000fd5
diff --git a/cmd/pinchtab/cmd_bridge.go b/cmd/pinchtab/cmd_bridge.go
index 6ec43f97..af49932f 100644
--- a/cmd/pinchtab/cmd_bridge.go
+++ b/cmd/pinchtab/cmd_bridge.go
@@ -39,6 +39,9 @@ func runBridgeServer(cfg *config.RuntimeConfig) {
})
}
h.RegisterRoutes(mux, doShutdown)
+ if cfg.AllowEvaluate && cfg.Token == "" {
+ slog.Warn("evaluate endpoint enabled without API token", "hint", "set PINCHTAB_TOKEN for authenticated access")
+ }
// HTTP server
server := &http.Server{
diff --git a/cmd/pinchtab/cmd_dashboard.go b/cmd/pinchtab/cmd_dashboard.go
index 8788601d..1080a923 100644
--- a/cmd/pinchtab/cmd_dashboard.go
+++ b/cmd/pinchtab/cmd_dashboard.go
@@ -108,6 +108,9 @@ func runDashboard(cfg *config.RuntimeConfig) {
})
handler := handlers.LoggingMiddleware(handlers.CorsMiddleware(handlers.AuthMiddleware(cfg, mux)))
+ if cfg.AllowEvaluate && cfg.Token == "" {
+ slog.Warn("evaluate endpoint enabled without API token", "hint", "set PINCHTAB_TOKEN for authenticated access")
+ }
srv := &http.Server{
Addr: cfg.Bind + ":" + dashPort,
diff --git a/docs/references/configuration.md b/docs/references/configuration.md
index eb90e09d..4fdd1fca 100644
--- a/docs/references/configuration.md
+++ b/docs/references/configuration.md
@@ -38,6 +38,7 @@ Complete reference for all PinchTab environment variables and configuration opti
| Variable | Default | Description |
|---|---|---|
| `BRIDGE_TOKEN` | Disabled | API authentication token (if set, all requests must include `Authorization: Bearer {token}`) |
+| `BRIDGE_ALLOW_EVALUATE` | `false` | Enable `POST /evaluate` and `POST /tabs/{id}/evaluate` endpoints (disabled by default) |
### Debugging & Logging
@@ -117,6 +118,16 @@ Then all API requests must include:
curl -H "Authorization: Bearer my-secret-token" http://localhost:9867/health
```
+### Enable JavaScript Evaluate Endpoint (Opt-in)
+
+```bash
+BRIDGE_TOKEN=my-secret-token \
+BRIDGE_ALLOW_EVALUATE=true \
+./pinchtab
+```
+
+By default, evaluate endpoints are not registered.
+
### Multiple Settings
```bash
diff --git a/internal/config/config.go b/internal/config/config.go
index a4fda600..bef46837 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -18,6 +18,7 @@ type RuntimeConfig struct {
InstancePortEnd int // Ending port for instances (default 9968)
CdpURL string
Token string
+ AllowEvaluate bool
StateDir string
Headless bool
NoRestore bool
@@ -220,6 +221,7 @@ type FileConfig struct {
InstancePortEnd *int `json:"instancePortEnd,omitempty"`
CdpURL string `json:"cdpUrl,omitempty"`
Token string `json:"token,omitempty"`
+ AllowEvaluate *bool `json:"allowEvaluate,omitempty"`
StateDir string `json:"stateDir"`
ProfileDir string `json:"profileDir"`
Headless *bool `json:"headless,omitempty"`
@@ -237,6 +239,7 @@ func Load() *RuntimeConfig {
InstancePortEnd: envIntOr("INSTANCE_PORT_END", 9968),
CdpURL: os.Getenv("CDP_URL"),
Token: envMigrate("PINCHTAB_TOKEN", "BRIDGE_TOKEN"),
+ AllowEvaluate: envBoolOrMigrate("PINCHTAB_ALLOW_EVALUATE", "BRIDGE_ALLOW_EVALUATE", false),
StateDir: envOrMigrate("PINCHTAB_STATE_DIR", "BRIDGE_STATE_DIR", userConfigDir()),
Headless: envBoolOrMigrate("PINCHTAB_HEADLESS", "BRIDGE_HEADLESS", true),
NoRestore: envBoolOrMigrate("PINCHTAB_NO_RESTORE", "BRIDGE_NO_RESTORE", false),
@@ -290,6 +293,9 @@ func Load() *RuntimeConfig {
if fc.Token != "" && !envMigrateIsSet("PINCHTAB_TOKEN", "BRIDGE_TOKEN") {
cfg.Token = fc.Token
}
+ if fc.AllowEvaluate != nil && !envMigrateIsSet("PINCHTAB_ALLOW_EVALUATE", "BRIDGE_ALLOW_EVALUATE") {
+ cfg.AllowEvaluate = *fc.AllowEvaluate
+ }
if fc.StateDir != "" && !envMigrateIsSet("PINCHTAB_STATE_DIR", "BRIDGE_STATE_DIR") {
cfg.StateDir = fc.StateDir
}
@@ -382,6 +388,7 @@ func HandleConfigCommand(cfg *RuntimeConfig) {
fmt.Printf(" Port: %s\n", cfg.Port)
fmt.Printf(" CDP URL: %s\n", cfg.CdpURL)
fmt.Printf(" Token: %s\n", MaskToken(cfg.Token))
+ fmt.Printf(" Eval JS: %v\n", cfg.AllowEvaluate)
fmt.Printf(" State Dir: %s\n", cfg.StateDir)
fmt.Printf(" Profile: %s\n", cfg.ProfileDir)
fmt.Printf(" Headless: %v\n", cfg.Headless)
diff --git a/internal/config/config_test.go b/internal/config/config_test.go
index 619f146e..e400fb2e 100644
--- a/internal/config/config_test.go
+++ b/internal/config/config_test.go
@@ -95,6 +95,8 @@ func TestLoadConfigDefaults(t *testing.T) {
_ = os.Unsetenv("CDP_URL")
_ = os.Unsetenv("PINCHTAB_TOKEN")
_ = os.Unsetenv("BRIDGE_TOKEN")
+ _ = os.Unsetenv("PINCHTAB_ALLOW_EVALUATE")
+ _ = os.Unsetenv("BRIDGE_ALLOW_EVALUATE")
cfg := Load()
if cfg.Port != "9867" {
@@ -103,27 +105,45 @@ func TestLoadConfigDefaults(t *testing.T) {
if cfg.Bind != "127.0.0.1" {
t.Errorf("default Bind = %v, want 127.0.0.1", cfg.Bind)
}
+ if cfg.AllowEvaluate {
+ t.Errorf("default AllowEvaluate = %v, want false", cfg.AllowEvaluate)
+ }
}
func TestLoadConfigEnvOverrides(t *testing.T) {
_ = os.Setenv("PINCHTAB_PORT", "1234")
- defer func() { _ = os.Unsetenv("PINCHTAB_PORT") }()
+ _ = os.Setenv("PINCHTAB_ALLOW_EVALUATE", "1")
+ defer func() {
+ _ = os.Unsetenv("PINCHTAB_PORT")
+ _ = os.Unsetenv("PINCHTAB_ALLOW_EVALUATE")
+ }()
cfg := Load()
if cfg.Port != "1234" {
t.Errorf("env Port = %v, want 1234", cfg.Port)
}
+ if !cfg.AllowEvaluate {
+ t.Errorf("env AllowEvaluate = %v, want true", cfg.AllowEvaluate)
+ }
}
func TestLegacyBridgeEnvFallback(t *testing.T) {
_ = os.Unsetenv("PINCHTAB_PORT")
+ _ = os.Unsetenv("PINCHTAB_ALLOW_EVALUATE")
_ = os.Setenv("BRIDGE_PORT", "5555")
- defer func() { _ = os.Unsetenv("BRIDGE_PORT") }()
+ _ = os.Setenv("BRIDGE_ALLOW_EVALUATE", "true")
+ defer func() {
+ _ = os.Unsetenv("BRIDGE_PORT")
+ _ = os.Unsetenv("BRIDGE_ALLOW_EVALUATE")
+ }()
cfg := Load()
if cfg.Port != "5555" {
t.Errorf("legacy fallback Port = %v, want 5555", cfg.Port)
}
+ if !cfg.AllowEvaluate {
+ t.Errorf("legacy fallback AllowEvaluate = %v, want true", cfg.AllowEvaluate)
+ }
}
func TestPinchtabEnvTakesPrecedence(t *testing.T) {
@@ -159,6 +179,7 @@ func TestLoadConfigFile(t *testing.T) {
// Create a dummy config file
configData := `{
"port": "8888",
+ "allowEvaluate": true,
"headless": false,
"timeoutSec": 60
}`
@@ -170,6 +191,9 @@ func TestLoadConfigFile(t *testing.T) {
if cfg.Port != "8888" {
t.Errorf("file Port = %v, want 8888", cfg.Port)
}
+ if cfg.AllowEvaluate != true {
+ t.Errorf("file AllowEvaluate = %v, want true", cfg.AllowEvaluate)
+ }
if cfg.Headless != false {
t.Errorf("file Headless = %v, want false", cfg.Headless)
}
diff --git a/internal/handlers/evaluate.go b/internal/handlers/evaluate.go
index b688f13b..9803586a 100644
--- a/internal/handlers/evaluate.go
+++ b/internal/handlers/evaluate.go
@@ -13,10 +13,19 @@ import (
"github.com/pinchtab/pinchtab/internal/web"
)
+func (h *Handlers) evaluateEnabled() bool {
+ return h != nil && h.Config != nil && h.Config.AllowEvaluate
+}
+
// HandleEvaluate runs JavaScript in the current tab.
//
// @Endpoint POST /evaluate
func (h *Handlers) HandleEvaluate(w http.ResponseWriter, r *http.Request) {
+ if !h.evaluateEnabled() {
+ web.ErrorCode(w, 403, "evaluate_disabled", "evaluate endpoint is disabled; set PINCHTAB_ALLOW_EVALUATE=1 to enable", false, nil)
+ return
+ }
+
var req struct {
TabID string `json:"tabId"`
Expression string `json:"expression"`
@@ -53,6 +62,11 @@ func (h *Handlers) HandleEvaluate(w http.ResponseWriter, r *http.Request) {
//
// @Endpoint POST /tabs/{id}/evaluate
func (h *Handlers) HandleTabEvaluate(w http.ResponseWriter, r *http.Request) {
+ if !h.evaluateEnabled() {
+ web.ErrorCode(w, 403, "evaluate_disabled", "evaluate endpoint is disabled; set PINCHTAB_ALLOW_EVALUATE=1 to enable", false, nil)
+ return
+ }
+
tabID := r.PathValue("id")
if tabID == "" {
web.Error(w, 400, fmt.Errorf("tab id required"))
diff --git a/internal/handlers/evaluate_test.go b/internal/handlers/evaluate_test.go
index eb066365..6e08a3a7 100644
--- a/internal/handlers/evaluate_test.go
+++ b/internal/handlers/evaluate_test.go
@@ -9,7 +9,7 @@ import (
)
func TestHandleEvaluate_InvalidJSON(t *testing.T) {
- h := New(&mockBridge{}, &config.RuntimeConfig{}, nil, nil, nil)
+ h := New(&mockBridge{}, &config.RuntimeConfig{AllowEvaluate: true}, nil, nil, nil)
req := httptest.NewRequest("POST", "/evaluate", bytes.NewReader([]byte(`not json`)))
w := httptest.NewRecorder()
h.HandleEvaluate(w, req)
@@ -19,7 +19,7 @@ func TestHandleEvaluate_InvalidJSON(t *testing.T) {
}
func TestHandleTabEvaluate_MissingTabID(t *testing.T) {
- h := New(&mockBridge{}, &config.RuntimeConfig{}, nil, nil, nil)
+ h := New(&mockBridge{}, &config.RuntimeConfig{AllowEvaluate: true}, nil, nil, nil)
req := httptest.NewRequest("POST", "/tabs//evaluate", bytes.NewReader([]byte(`{"expression":"1+1"}`)))
w := httptest.NewRecorder()
h.HandleTabEvaluate(w, req)
@@ -29,7 +29,7 @@ func TestHandleTabEvaluate_MissingTabID(t *testing.T) {
}
func TestHandleTabEvaluate_TabIDMismatch(t *testing.T) {
- h := New(&mockBridge{}, &config.RuntimeConfig{}, nil, nil, nil)
+ h := New(&mockBridge{}, &config.RuntimeConfig{AllowEvaluate: true}, nil, nil, nil)
req := httptest.NewRequest("POST", "/tabs/tab_abc/evaluate", bytes.NewReader([]byte(`{"tabId":"tab_other","expression":"1+1"}`)))
req.SetPathValue("id", "tab_abc")
w := httptest.NewRecorder()
@@ -40,7 +40,7 @@ func TestHandleTabEvaluate_TabIDMismatch(t *testing.T) {
}
func TestHandleTabEvaluate_NoTab(t *testing.T) {
- h := New(&mockBridge{failTab: true}, &config.RuntimeConfig{}, nil, nil, nil)
+ h := New(&mockBridge{failTab: true}, &config.RuntimeConfig{AllowEvaluate: true}, nil, nil, nil)
req := httptest.NewRequest("POST", "/tabs/tab_abc/evaluate", bytes.NewReader([]byte(`{"expression":"1+1"}`)))
req.SetPathValue("id", "tab_abc")
w := httptest.NewRecorder()
@@ -49,3 +49,24 @@ func TestHandleTabEvaluate_NoTab(t *testing.T) {
t.Errorf("expected 404, got %d", w.Code)
}
}
+
+func TestHandleEvaluate_Disabled(t *testing.T) {
+ h := New(&mockBridge{}, &config.RuntimeConfig{}, nil, nil, nil)
+ req := httptest.NewRequest("POST", "/evaluate", bytes.NewReader([]byte(`{"expression":"1+1"}`)))
+ w := httptest.NewRecorder()
+ h.HandleEvaluate(w, req)
+ if w.Code != 403 {
+ t.Errorf("expected 403, got %d", w.Code)
+ }
+}
+
+func TestHandleTabEvaluate_Disabled(t *testing.T) {
+ h := New(&mockBridge{}, &config.RuntimeConfig{}, nil, nil, nil)
+ req := httptest.NewRequest("POST", "/tabs/tab_abc/evaluate", bytes.NewReader([]byte(`{"expression":"1+1"}`)))
+ req.SetPathValue("id", "tab_abc")
+ w := httptest.NewRecorder()
+ h.HandleTabEvaluate(w, req)
+ if w.Code != 403 {
+ t.Errorf("expected 403, got %d", w.Code)
+ }
+}
diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go
index e678d780..d8655471 100644
--- a/internal/handlers/handlers.go
+++ b/internal/handlers/handlers.go
@@ -95,7 +95,6 @@ func (h *Handlers) RegisterRoutes(mux *http.ServeMux, doShutdown func()) {
mux.HandleFunc("POST /tabs/{id}/action", h.HandleTabAction)
mux.HandleFunc("POST /tabs/{id}/actions", h.HandleTabActions)
mux.HandleFunc("GET /tabs/{id}/text", h.HandleTabText)
- mux.HandleFunc("POST /tabs/{id}/evaluate", h.HandleTabEvaluate)
mux.HandleFunc("GET /tabs/{id}/metrics", h.HandleTabMetrics)
mux.HandleFunc("GET /metrics", h.HandleMetrics)
mux.HandleFunc("GET /snapshot", h.HandleSnapshot)
@@ -112,7 +111,6 @@ func (h *Handlers) RegisterRoutes(mux *http.ServeMux, doShutdown func()) {
mux.HandleFunc("GET /action", h.HandleAction)
mux.HandleFunc("POST /actions", h.HandleActions)
mux.HandleFunc("POST /macro", h.HandleMacro)
- mux.HandleFunc("POST /evaluate", h.HandleEvaluate)
mux.HandleFunc("POST /tab", h.HandleTab)
mux.HandleFunc("POST /tab/lock", h.HandleTabLock)
mux.HandleFunc("POST /tab/unlock", h.HandleTabUnlock)
@@ -131,6 +129,10 @@ func (h *Handlers) RegisterRoutes(mux *http.ServeMux, doShutdown func()) {
mux.HandleFunc("POST /find", h.HandleFind)
mux.HandleFunc("GET /screencast", h.HandleScreencast)
mux.HandleFunc("GET /screencast/tabs", h.HandleScreencastAll)
+ if h.Config != nil && h.Config.AllowEvaluate {
+ mux.HandleFunc("POST /tabs/{id}/evaluate", h.HandleTabEvaluate)
+ mux.HandleFunc("POST /evaluate", h.HandleEvaluate)
+ }
mux.HandleFunc("GET /welcome", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
_, _ = w.Write([]byte(assets.WelcomeHTML))
diff --git a/internal/handlers/handlers_test.go b/internal/handlers/handlers_test.go
index bbc2ee43..c759e6c9 100644
--- a/internal/handlers/handlers_test.go
+++ b/internal/handlers/handlers_test.go
@@ -211,3 +211,29 @@ func TestRoutesRegistration(t *testing.T) {
}
}
}
+
+func TestEvaluateRouteNotRegisteredByDefault(t *testing.T) {
+ h := New(&mockBridge{}, &config.RuntimeConfig{}, nil, nil, nil)
+ mux := http.NewServeMux()
+ h.RegisterRoutes(mux, nil)
+
+ req := httptest.NewRequest("POST", "/evaluate", bytes.NewReader([]byte(`{"expression":"1+1"}`)))
+ w := httptest.NewRecorder()
+ mux.ServeHTTP(w, req)
+ if w.Code != 404 {
+ t.Fatalf("expected 404 when evaluate is disabled, got %d", w.Code)
+ }
+}
+
+func TestEvaluateRouteRegisteredWhenEnabled(t *testing.T) {
+ h := New(&mockBridge{}, &config.RuntimeConfig{AllowEvaluate: true}, nil, nil, nil)
+ mux := http.NewServeMux()
+ h.RegisterRoutes(mux, nil)
+
+ req := httptest.NewRequest("POST", "/evaluate", bytes.NewReader([]byte(`not json`)))
+ w := httptest.NewRecorder()
+ mux.ServeHTTP(w, req)
+ if w.Code != 400 {
+ t.Fatalf("expected evaluate route to be active, got %d", w.Code)
+ }
+}
diff --git a/internal/handlers/middleware.go b/internal/handlers/middleware.go
index 5f6d02eb..6c301626 100644
--- a/internal/handlers/middleware.go
+++ b/internal/handlers/middleware.go
@@ -49,13 +49,24 @@ func AuthMiddleware(cfg *config.RuntimeConfig, next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if cfg.Token != "" {
auth := r.Header.Get("Authorization")
- if auth == "" {
+ qToken := r.URL.Query().Get("token")
+
+ if auth == "" && qToken == "" {
w.Header().Set("WWW-Authenticate", `Bearer realm="pinchtab", error="missing_token"`)
web.ErrorCode(w, 401, "missing_token", "unauthorized", false, nil)
return
}
- expected := "Bearer " + cfg.Token
- if subtle.ConstantTimeCompare([]byte(auth), []byte(expected)) != 1 {
+
+ provided := strings.TrimPrefix(auth, "Bearer ")
+ if provided == auth { // "Bearer " prefix was not present
+ if qToken != "" {
+ provided = qToken
+ } else {
+ provided = auth
+ }
+ }
+
+ if subtle.ConstantTimeCompare([]byte(provided), []byte(cfg.Token)) != 1 {
w.Header().Set("WWW-Authenticate", `Bearer realm="pinchtab", error="bad_token"`)
web.ErrorCode(w, 401, "bad_token", "unauthorized", false, nil)
return
diff --git a/internal/handlers/screencast.go b/internal/handlers/screencast.go
index 88845417..a7332cfd 100644
--- a/internal/handlers/screencast.go
+++ b/internal/handlers/screencast.go
@@ -2,12 +2,10 @@ package handlers
import (
"context"
- "crypto/subtle"
"encoding/base64"
"fmt"
"log/slog"
"net/http"
- "strings"
"sync"
"time"
@@ -21,22 +19,6 @@ import (
// HandleScreencast upgrades to WebSocket and streams screencast frames for a tab.
// Query params: tabId (required), quality (1-100, default 40), maxWidth (default 800), fps (1-30, default 5)
func (h *Handlers) HandleScreencast(w http.ResponseWriter, r *http.Request) {
- // WebSocket auth: check query param token or Authorization header.
- // WebSocket clients typically can't set custom headers during the
- // upgrade handshake, so we accept the token as a query parameter.
- if h.Config.Token != "" {
- qToken := r.URL.Query().Get("token")
- authHeader := r.Header.Get("Authorization")
- provided := strings.TrimPrefix(authHeader, "Bearer ")
- if provided == "" {
- provided = qToken
- }
- if provided == "" || subtle.ConstantTimeCompare([]byte(provided), []byte(h.Config.Token)) != 1 {
- http.Error(w, "unauthorized", http.StatusUnauthorized)
- return
- }
- }
-
tabID := r.URL.Query().Get("tabId")
if tabID == "" {
targets, err := h.Bridge.ListTargets()
diff --git a/internal/handlers/screencast_test.go b/internal/handlers/screencast_test.go
index 10581e34..5df60514 100644
--- a/internal/handlers/screencast_test.go
+++ b/internal/handlers/screencast_test.go
@@ -14,7 +14,8 @@ func TestHandleScreencast_AuthRejectsNoToken(t *testing.T) {
req := httptest.NewRequest("GET", "/screencast", nil)
w := httptest.NewRecorder()
- h.HandleScreencast(w, req)
+ handler := AuthMiddleware(cfg, http.HandlerFunc(h.HandleScreencast))
+ handler.ServeHTTP(w, req)
if w.Code != http.StatusUnauthorized {
t.Errorf("expected 401 Unauthorized without token, got %d", w.Code)
@@ -27,7 +28,8 @@ func TestHandleScreencast_AuthRejectsWrongToken(t *testing.T) {
req := httptest.NewRequest("GET", "/screencast?token=wrong-token", nil)
w := httptest.NewRecorder()
- h.HandleScreencast(w, req)
+ handler := AuthMiddleware(cfg, http.HandlerFunc(h.HandleScreencast))
+ handler.ServeHTTP(w, req)
if w.Code != http.StatusUnauthorized {
t.Errorf("expected 401 Unauthorized with wrong token, got %d", w.Code)
@@ -41,7 +43,8 @@ func TestHandleScreencast_AuthRejectsWrongHeader(t *testing.T) {
req := httptest.NewRequest("GET", "/screencast", nil)
req.Header.Set("Authorization", "Bearer wrong-token")
w := httptest.NewRecorder()
- h.HandleScreencast(w, req)
+ handler := AuthMiddleware(cfg, http.HandlerFunc(h.HandleScreencast))
+ handler.ServeHTTP(w, req)
if w.Code != http.StatusUnauthorized {
t.Errorf("expected 401 Unauthorized with wrong Bearer header, got %d", w.Code)
@@ -57,7 +60,8 @@ func TestHandleScreencast_NoTokenConfigSkipsAuth(t *testing.T) {
// didn't block the request.
req := httptest.NewRequest("GET", "/screencast", nil)
w := httptest.NewRecorder()
- h.HandleScreencast(w, req)
+ handler := AuthMiddleware(cfg, http.HandlerFunc(h.HandleScreencast))
+ handler.ServeHTTP(w, req)
if w.Code == http.StatusUnauthorized {
t.Errorf("should not get 401 when no token is configured, got %d", w.Code)
diff --git a/internal/orchestrator/handlers.go b/internal/orchestrator/handlers.go
index 53312bd5..ee8b777c 100644
--- a/internal/orchestrator/handlers.go
+++ b/internal/orchestrator/handlers.go
@@ -39,7 +39,6 @@ func (o *Orchestrator) RegisterHandlers(mux *http.ServeMux) {
"POST /tabs/{id}/action",
"POST /tabs/{id}/actions",
"GET /tabs/{id}/text",
- "POST /tabs/{id}/evaluate",
"GET /tabs/{id}/pdf",
"POST /tabs/{id}/pdf",
"GET /tabs/{id}/download",
@@ -51,6 +50,9 @@ func (o *Orchestrator) RegisterHandlers(mux *http.ServeMux) {
"GET /tabs/{id}/metrics",
"POST /tabs/{id}/find",
}
+ if o.allowEvaluate {
+ tabProxyRoutes = append(tabProxyRoutes, "POST /tabs/{id}/evaluate")
+ }
for _, route := range tabProxyRoutes {
mux.HandleFunc(route, o.proxyTabRequest)
}
diff --git a/internal/orchestrator/orchestrator.go b/internal/orchestrator/orchestrator.go
index d5bf21d9..c95a6ecb 100644
--- a/internal/orchestrator/orchestrator.go
+++ b/internal/orchestrator/orchestrator.go
@@ -29,6 +29,20 @@ func envWithFallback(newKey, oldKey string) string {
return os.Getenv(oldKey)
}
+func envBoolWithFallback(newKey, oldKey string, fallback bool) bool {
+ v := strings.TrimSpace(strings.ToLower(envWithFallback(newKey, oldKey)))
+ switch v {
+ case "1", "true", "yes", "on":
+ return true
+ case "0", "false", "no", "off":
+ return false
+ case "":
+ return fallback
+ default:
+ return fallback
+ }
+}
+
// InstanceEvent is emitted when instance state changes.
type InstanceEvent struct {
Type string `json:"type"` // "instance.started", "instance.stopped", "instance.error"
@@ -47,6 +61,7 @@ type Orchestrator struct {
mu sync.RWMutex
client *http.Client
childAuthToken string
+ allowEvaluate bool
portAllocator *PortAllocator
idMgr *idutil.Manager
eventHandlers []EventHandler
@@ -134,6 +149,7 @@ func NewOrchestratorWithRunner(baseDir string, runner HostRunner) *Orchestrator
// See: internal/orchestrator/health.go (monitor), internal/bridge/init.go (InitChrome)
client: &http.Client{Timeout: 60 * time.Second},
childAuthToken: envWithFallback("PINCHTAB_TOKEN", "BRIDGE_TOKEN"),
+ allowEvaluate: envBoolWithFallback("PINCHTAB_ALLOW_EVALUATE", "BRIDGE_ALLOW_EVALUATE", false),
portAllocator: NewPortAllocator(9868, 9968),
idMgr: idutil.NewManager(),
}