Skip to content

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

fix: --server redirects the destination but the credential stays ambient, so pointing the CLI at any host sends the local config's server.token to it in cleartext (PIN-247)

Luigi Agostic65bccc70cfc
diff --git a/.gitignore b/.gitignore
index 604b941a..b70c58c4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -74,3 +74,10 @@ todo.md
todo-user.md
review-next.md
.alp/
+
+# Auto-named capture artefacts a live CLI run drops into the working directory. The names
+# come from exportTimestamp, so they are never intentional source files.
+screenshot-[0-9]*.jpg
+screenshot-[0-9]*.png
+capture-[0-9]*.jpg
+capture-[0-9]*.png
diff --git a/cmd/pinchtab/cmd_cli_runtime.go b/cmd/pinchtab/cmd_cli_runtime.go
index 9a88965c..7ae1f8a8 100644
--- a/cmd/pinchtab/cmd_cli_runtime.go
+++ b/cmd/pinchtab/cmd_cli_runtime.go
@@ -146,7 +146,13 @@ func resolveDefaultCLIBase(cfg *config.RuntimeConfig) string {
// config file's. The tab probe used the env-only resolvers with a hardcoded 9867
// fallback, so with a configured port it probed a different server than the command
// — found nothing listening, assumed the stale tab valid, and refreshed its own
-// freshness window. Same target, same credential, or the probe cannot self-heal.
+// freshness window. Same target, so the probe can self-heal.
+//
+// The credential is the same EXCEPT against a non-loopback base with only the config
+// file's server.token: there the probe DEGRADES to an unauthenticated request rather
+// than exiting, because it runs on every command and must not kill one that would
+// refuse properly at its own site. Either way the config token does not leave the
+// machine; the probe simply learns less.
var resolveTabStateEndpoint = func() (base, token string) {
cfg := config.Load()
base = resolveBaseURL(resolveDefaultCLIBase(cfg))
@@ -189,12 +195,18 @@ func resolveCLIToken(cfg *config.RuntimeConfig, base string) (string, error) {
apiclient.UseTokenSource("the PINCHTAB_TOKEN environment variable")
return t, nil
}
+ // The emptiness test comes FIRST: with no server.token there is nothing to withhold, so
+ // refusing would name a secret that does not exist and would break a legitimate flow —
+ // a tokenless server on a LAN or in Docker — for no security gain. That is the same test
+ // the loopback predicate itself was chosen by. With no credential the remote answers its
+ // own honest 401.
+ if cfg.Token == "" {
+ return "", nil
+ }
if !loopbackBase(base) {
return "", fmt.Errorf("refusing to send the local config's server.token to %s: set PINCHTAB_TOKEN (or PINCHTAB_SESSION) with the credential for that host", base)
}
- if cfg.Token != "" {
- apiclient.UseTokenSource("server.token in " + cliTokenConfigPath())
- }
+ apiclient.UseTokenSource("server.token in " + cliTokenConfigPath())
return cfg.Token, nil
}
diff --git a/cmd/pinchtab/remote_token_guard_test.go b/cmd/pinchtab/remote_token_guard_test.go
index 091d920a..58083702 100644
--- a/cmd/pinchtab/remote_token_guard_test.go
+++ b/cmd/pinchtab/remote_token_guard_test.go
@@ -130,6 +130,44 @@ func TestTheConfigTokenStillServesEveryLoopbackShape(t *testing.T) {
}
}
+// With no server.token there is nothing to withhold, so refusing would name a secret that
+// does not exist AND break a legitimate flow — a tokenless server on a LAN or in Docker,
+// which internal/cli/report/security.go treats as supported-but-warned rather than
+// impossible. Nothing leaves the machine either way, so the refusal buys nothing: exactly
+// the test the loopback predicate was chosen by. The remote answers its own honest 401.
+//
+// This was invisible because every other refusal test sets a config token.
+func TestAnEmptyConfigTokenIsNotRefused(t *testing.T) {
+ clearCredentialEnv(t)
+ cfg := &config.RuntimeConfig{Port: "9867", Token: ""}
+
+ token, err := resolveCLIToken(cfg, "http://203.0.113.9:9867")
+ if err != nil {
+ t.Fatalf("a tokenless config was refused against a remote host: %v — nothing would have been sent, so this is breakage with no security gain", err)
+ }
+ if token != "" {
+ t.Errorf("token = %q, want empty so the remote answers its own 401", token)
+ }
+}
+
+// The refusal survives for the case it exists for: the same remote host WITH a config token.
+// Paired with the test above so a fix that simply deleted the guard cannot pass both.
+func TestAPresentConfigTokenIsStillRefusedForTheSameHost(t *testing.T) {
+ clearCredentialEnv(t)
+ cfg := &config.RuntimeConfig{Port: "9867", Token: "local-secret"}
+
+ token, err := resolveCLIToken(cfg, "http://203.0.113.9:9867")
+ if err == nil {
+ t.Fatal("a config token was handed to a remote host; that is the leak this card closes")
+ }
+ if token != "" {
+ t.Errorf("token = %q returned alongside the refusal", token)
+ }
+ if !strings.Contains(err.Error(), "server.token") {
+ t.Errorf("refusal %q no longer names what it is withholding", err)
+ }
+}
+
func TestAnEnvCredentialTravelsToAnyHost(t *testing.T) {
clearCredentialEnv(t)
t.Setenv("PINCHTAB_TOKEN", "remote-secret")
diff --git a/docs/guides/mcp-agents.md b/docs/guides/mcp-agents.md
index f4e00d55..a0f107cb 100644
--- a/docs/guides/mcp-agents.md
+++ b/docs/guides/mcp-agents.md
@@ -111,9 +111,15 @@ proc = subprocess.Popen(
|----------|---------|-------------|
| `PINCHTAB_TOKEN` | *(from config)* | Bearer token for auth-protected servers |
-For remote servers, use the `--server` flag: `pinchtab --server http://remote:9867 mcp`
+For remote servers, use the `--server` flag with that host's credential — a non-loopback host
+requires `PINCHTAB_TOKEN` (or `PINCHTAB_SESSION`), since the CLI refuses to send the local
+config's `server.token` off the machine:
-`PINCHTAB_TOKEN` comes from `server.token` in your PinchTab config file. To copy the current token without printing it to stdout, run `pinchtab config token`.
+```bash
+PINCHTAB_TOKEN=<that-host-token> pinchtab --server http://remote:9867 mcp
+```
+
+`PINCHTAB_TOKEN` comes from `server.token` in your PinchTab config file — that is the credential for your LOCAL server, not for a remote one. To copy the current token without printing it to stdout, run `pinchtab config token`.
## Typical Agent Workflow