Skip to content

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

fix: drop client-supplied websocket proxy authorization when no instance token is set

Luigi Agostid9a83c004c95
diff --git a/internal/orchestrator/proxy.go b/internal/orchestrator/proxy.go
index ef5146b3..14cf373d 100644
--- a/internal/orchestrator/proxy.go
+++ b/internal/orchestrator/proxy.go
@@ -317,6 +317,11 @@ func (o *Orchestrator) applyInstanceAuth(req *http.Request, inst *InstanceIntern
if req == nil || inst == nil {
return
}
+ // Clear before setting: the WebSocket header filter promotes
+ // X-Pinchtab-Proxy-Authorization into Authorization on the connection to the
+ // instance, so a client-supplied value must not survive when we have no
+ // token of our own to overwrite it with.
+ iproxy.SetProxyWSBackendAuthorization(req.Header, "")
token := inst.authToken
if token == "" {
token = o.childAuthToken
diff --git a/internal/orchestrator/proxy_ws_auth_test.go b/internal/orchestrator/proxy_ws_auth_test.go
new file mode 100644
index 00000000..b32560c4
--- /dev/null
+++ b/internal/orchestrator/proxy_ws_auth_test.go
@@ -0,0 +1,46 @@
+package orchestrator
+
+import (
+ "net/http"
+ "testing"
+)
+
+// The WebSocket header filter in internal/proxy promotes
+// X-Pinchtab-Proxy-Authorization into Authorization on the orchestrator →
+// instance connection. It is an internal channel, so a value arriving from the
+// client must never survive — including when the orchestrator has no token of
+// its own to overwrite it with. The /screencast path clears it unconditionally
+// before setting; applyInstanceAuth must do the same.
+func TestApplyInstanceAuthDropsClientSuppliedWSAuthorization(t *testing.T) {
+ const header = "X-Pinchtab-Proxy-Authorization"
+
+ tests := []struct {
+ name string
+ instanceToken string
+ childToken string
+ want string
+ }{
+ {name: "no tokens configured", want: ""},
+ {name: "instance token wins", instanceToken: "real-token", want: "Bearer real-token"},
+ {name: "child token used", childToken: "child-token", want: "Bearer child-token"},
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ o := &Orchestrator{childAuthToken: tt.childToken}
+ inst := &InstanceInternal{authToken: tt.instanceToken}
+
+ req, err := http.NewRequest(http.MethodGet, "http://instance/screencast", nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ req.Header.Set(header, "Bearer attacker-supplied")
+
+ o.applyInstanceAuth(req, inst)
+
+ if got := req.Header.Get(header); got != tt.want {
+ t.Errorf("%s = %q, want %q", header, got, tt.want)
+ }
+ })
+ }
+}