Skip to content

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

fix: revert the ineffective scheduler env internal-token; census pending-exempts the scheduler until orchestrator hop-auth routing lands (PIN-384)

Luigi Agostic1bc0d743cfd
diff --git a/internal/api/types/headers_census_test.go b/internal/api/types/headers_census_test.go
index 8f5d96d5..1a846b5e 100644
--- a/internal/api/types/headers_census_test.go
+++ b/internal/api/types/headers_census_test.go
@@ -191,6 +191,17 @@ var publicClientPackages = map[string]string{
var publicClientExemptHeaders = map[string]map[string]string{
"internal/cli/apiclient": {"x-pinchtab-source": "harmless: bearer credential fallback records the same 'client' label"},
"cmd/pinchtab": {"x-pinchtab-source": "harmless: same as the CLI apiclient — bearer fallback yields 'client'"},
+ // PENDING (PIN-384, blocked): the scheduler's Source/Tab-Id are stripped today, so it
+ // records as 'client'. The fix is to send the trusted internal token via the
+ // orchestrator's hop-auth owner (applyInstanceAuth) — which lives outside this card's
+ // footprint (orchestrator/scheduler interface/server wiring). Remove these two entries
+ // when that lands and the executor routes through the authorizer.
+ "internal/scheduler": {
+ "x-pinchtab-source": "PENDING PIN-384: needs the orchestrator internal-token hop-auth; stripped until then",
+ "x-pinchtab-tab-id": "PENDING PIN-384: needs the orchestrator internal-token hop-auth; stripped until then",
+ "x-pinchtab-event": "webhook.go: outbound event-webhook to an EXTERNAL receiver that reads these; not a PinchTab listener behind the strip layer",
+ "x-pinchtab-task-id": "webhook.go: outbound event-webhook to an EXTERNAL receiver that reads these; not a PinchTab listener behind the strip layer",
+ },
}
func resolveHeaderName(arg ast.Expr) (string, bool) {
diff --git a/internal/scheduler/executor.go b/internal/scheduler/executor.go
index db36db12..625954d9 100644
--- a/internal/scheduler/executor.go
+++ b/internal/scheduler/executor.go
@@ -9,10 +9,8 @@ import (
"net"
"net/http"
"net/url"
- "os"
"github.com/pinchtab/pinchtab/internal/activity"
- "github.com/pinchtab/pinchtab/internal/handlers"
)
// TaskExecutor runs a single task and returns its result, decoupling dispatch
@@ -86,15 +84,6 @@ func (e *actionEndpointExecutor) Execute(ctx context.Context, t *Task) (any, err
return nil, fmt.Errorf("failed to create request: %w", err)
}
req.Header.Set("Content-Type", "application/json")
- // The instance strips inbound X-PinchTab-* headers unless the request carries the
- // trusted internal token, so the source and tab-id below would be a silent no-op
- // without it. The scheduler runs in the instance process, which holds the same
- // PINCHTAB_INTERNAL_TOKEN the ingress checks; when it is unset (single-instance,
- // no trust configured) the strip is total by design and the action records as
- // "client".
- if tok := os.Getenv("PINCHTAB_INTERNAL_TOKEN"); tok != "" {
- req.Header.Set(handlers.InternalTokenHeader, tok)
- }
req.Header.Set(activity.HeaderPTSource, "scheduler")
req.Header.Set(activity.HeaderPTTabID, t.TabID)
if t.AgentID != "" {
diff --git a/internal/scheduler/executor_test.go b/internal/scheduler/executor_test.go
index 87da92ac..988994cd 100644
--- a/internal/scheduler/executor_test.go
+++ b/internal/scheduler/executor_test.go
@@ -1,90 +1,6 @@
package scheduler
-import (
- "context"
- "net/http"
- "net/http/httptest"
- "net/url"
- "sync"
- "testing"
-
- "github.com/pinchtab/pinchtab/internal/activity"
- "github.com/pinchtab/pinchtab/internal/handlers"
-)
-
-type captureRecorder struct {
- mu sync.Mutex
- events []activity.Event
-}
-
-func (c *captureRecorder) Enabled() bool { return true }
-func (c *captureRecorder) Record(e activity.Event) error {
- c.mu.Lock()
- c.events = append(c.events, e)
- c.mu.Unlock()
- return nil
-}
-func (c *captureRecorder) Query(activity.Filter) ([]activity.Event, error) { return nil, nil }
-func (c *captureRecorder) last() (activity.Event, bool) {
- c.mu.Lock()
- defer c.mu.Unlock()
- if len(c.events) == 0 {
- return activity.Event{}, false
- }
- return c.events[len(c.events)-1], true
-}
-
-type fixedResolver struct{ port string }
-
-func (f fixedResolver) ResolveTabInstance(string) (string, error) { return f.port, nil }
-
-// The scheduler must record its actions as "scheduler", not "client": it now carries the
-// trusted internal token so its X-PinchTab-Source and X-PinchTab-Tab-Id survive the ingress
-// strip layer. Driven through the real TrustedInternalProxyStripMiddleware (the layer the
-// bridge mounts) plus activity.Middleware (the recorder). On HEAD the executor sends no
-// token, the strip drops both headers, and the source falls back to "client".
-func TestSchedulerActionSurvivesIngressAndRecordsAsScheduler(t *testing.T) {
- const secret = "test-internal-token"
- t.Setenv("PINCHTAB_INTERNAL_TOKEN", secret)
-
- var gotSource, gotTabID string
- final := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- gotSource = r.Header.Get(activity.HeaderPTSource)
- gotTabID = r.Header.Get(activity.HeaderPTTabID)
- w.WriteHeader(http.StatusOK)
- _, _ = w.Write([]byte(`{"ok":true}`))
- })
- rec := &captureRecorder{}
- handler := handlers.TrustedInternalProxyStripMiddleware(secret)(activity.Middleware(rec, "fallback", final))
- srv := httptest.NewServer(handler)
- defer srv.Close()
-
- parsed, err := url.Parse(srv.URL)
- if err != nil {
- t.Fatal(err)
- }
- exec := &actionEndpointExecutor{resolver: fixedResolver{port: parsed.Port()}, client: srv.Client()}
- if _, err := exec.Execute(context.Background(), &Task{Action: "click", Ref: "e5", TabID: "tab-42"}); err != nil {
- t.Fatalf("Execute: %v", err)
- }
-
- if gotSource != "scheduler" {
- t.Errorf("inbound X-PinchTab-Source = %q, want scheduler (the internal token must let it survive the strip layer)", gotSource)
- }
- if gotTabID != "tab-42" {
- t.Errorf("inbound X-PinchTab-Tab-Id = %q, want tab-42 (the tab id header must survive, not fall back to the path)", gotTabID)
- }
- evt, ok := rec.last()
- if !ok {
- t.Fatal("no activity event recorded")
- }
- if evt.Source != "scheduler" {
- t.Errorf("recorded activity source = %q, want scheduler", evt.Source)
- }
- if evt.TabID != "tab-42" {
- t.Errorf("recorded activity tab id = %q, want tab-42", evt.TabID)
- }
-}
+import "testing"
func TestBuildActionBodyEnvelope(t *testing.T) {
task := &Task{