Skip to content

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

fix: redact config secrets without breaking saves

Luigi Agosti542e5a75d9c4
diff --git a/dashboard/src/pages/SettingsPage.test.tsx b/dashboard/src/pages/SettingsPage.test.tsx
index 4ab79310..7b8a12e4 100644
--- a/dashboard/src/pages/SettingsPage.test.tsx
+++ b/dashboard/src/pages/SettingsPage.test.tsx
@@ -77,7 +77,7 @@ describe("SettingsPage", () => {
expect(
screen.getByText(
- "Dashboard edits are written back to this file. External provider keys stay under autoSolver.external in the same config.",
+ "Dashboard edits are written back to this file. Set external provider keys under autoSolver.external in the same config file.",
),
).toBeInTheDocument();
expect(screen.getByText("/tmp/config.json")).toBeInTheDocument();
diff --git a/dashboard/src/pages/settings/AutoSolverSettingsSection.tsx b/dashboard/src/pages/settings/AutoSolverSettingsSection.tsx
index f562d979..c9e2cd9d 100644
--- a/dashboard/src/pages/settings/AutoSolverSettingsSection.tsx
+++ b/dashboard/src/pages/settings/AutoSolverSettingsSection.tsx
@@ -17,11 +17,11 @@ export function AutoSolverSettingsSection({
return (
<SectionCard
title="AutoSolver"
- description="These settings are saved into the PinchTab config file. External provider API keys are config-file-only and are not read from environment variables."
+ description="These settings are saved into the PinchTab config file. External provider API keys stay write-only and must be set directly in that file."
>
<SettingRow
label="Config file"
- description="Dashboard edits are written back to this file. External provider keys stay under autoSolver.external in the same config."
+ description="Dashboard edits are written back to this file. Set external provider keys under autoSolver.external in the same config file."
>
<div className="rounded-sm border border-border-subtle bg-[rgb(var(--brand-surface-code-rgb)/0.72)] px-3 py-2 text-sm text-text-secondary">
<code>{backendState?.configPath || "Config path unavailable"}</code>
@@ -109,13 +109,14 @@ export function AutoSolverSettingsSection({
</SettingRow>
<SettingRow
label="External provider keys"
- description="Capsolver and 2Captcha credentials are only stored in the config file under autoSolver.external."
+ description="Capsolver and 2Captcha credentials are not shown in the dashboard and must be managed in the config file."
>
<div className="rounded-sm border border-warning/25 bg-warning/10 px-3 py-2 text-xs leading-5 text-warning">
- Use the config file for <code>autoSolver.external.capsolverKey</code>{" "}
- and <code>autoSolver.external.twoCaptchaKey</code>. The dashboard does
- not read or edit those values, and there are no
- <code> PINCHTAB_AUTOSOLVER_*</code> environment variable overrides.
+ Open the config file above and set{" "}
+ <code>autoSolver.external.capsolverKey</code> and{" "}
+ <code>autoSolver.external.twoCaptchaKey</code> there. The dashboard
+ does not display or edit those values, and there are no environment
+ variable overrides.
</div>
</SettingRow>
</SectionCard>
diff --git a/internal/config/config_file.go b/internal/config/config_file.go
index ba941e61..e80e6b3b 100644
--- a/internal/config/config_file.go
+++ b/internal/config/config_file.go
@@ -380,6 +380,7 @@ func (fc FileConfig) MarshalJSON() ([]byte, error) {
AllowUpload: fc.Security.AllowUpload,
AllowClipboard: fc.Security.AllowClipboard,
AllowStateExport: fc.Security.AllowStateExport,
+ StateEncryptionKey: fc.Security.StateEncryptionKey,
EnableActionGuards: fc.Security.EnableActionGuards,
UploadMaxRequestBytes: fc.Security.UploadMaxRequestBytes,
UploadMaxFiles: fc.Security.UploadMaxFiles,
diff --git a/internal/dashboard/config_api.go b/internal/dashboard/config_api.go
index 766e8763..c8336378 100644
--- a/internal/dashboard/config_api.go
+++ b/internal/dashboard/config_api.go
@@ -171,7 +171,7 @@ func (c *ConfigAPI) HandlePutConfig(w http.ResponseWriter, r *http.Request) {
})
return
}
- normalized.Server.Token = current.Server.Token
+ preserveWriteOnlyConfigFields(&normalized, current)
if err := config.SaveFileConfig(&normalized, path); err != nil {
httpx.Error(w, 500, err)
return
@@ -269,9 +269,22 @@ func (c *ConfigAPI) tokenConfigured(cfg config.FileConfig) bool {
func redactToken(cfg config.FileConfig) config.FileConfig {
cfg.Server.Token = ""
+ cfg.Security.StateEncryptionKey = nil
+ cfg.AutoSolver.External.CapsolverKey = ""
+ cfg.AutoSolver.External.TwoCaptchaKey = ""
return cfg
}
+func preserveWriteOnlyConfigFields(dst, src *config.FileConfig) {
+ if dst == nil || src == nil {
+ return
+ }
+ dst.Server.Token = src.Server.Token
+ dst.Security.StateEncryptionKey = src.Security.StateEncryptionKey
+ dst.AutoSolver.External.CapsolverKey = src.AutoSolver.External.CapsolverKey
+ dst.AutoSolver.External.TwoCaptchaKey = src.AutoSolver.External.TwoCaptchaKey
+}
+
func (c *ConfigAPI) restartReasonsFor(next config.FileConfig) []string {
reasons := make([]string, 0, 5)
diff --git a/internal/dashboard/config_api_test.go b/internal/dashboard/config_api_test.go
index 550f1b0b..d77c5f5e 100644
--- a/internal/dashboard/config_api_test.go
+++ b/internal/dashboard/config_api_test.go
@@ -7,6 +7,7 @@ import (
"net/http/httptest"
"os"
"path/filepath"
+ "reflect"
"slices"
"strings"
"testing"
@@ -92,6 +93,10 @@ func TestRestartReasonsIncludeStealthLevel(t *testing.T) {
func TestHandleGetConfigRedactsToken(t *testing.T) {
fc := config.DefaultFileConfig()
fc.Server.Token = "secret-token"
+ stateKey := "state-secret"
+ fc.Security.StateEncryptionKey = &stateKey
+ fc.AutoSolver.External.CapsolverKey = "capsolver-secret"
+ fc.AutoSolver.External.TwoCaptchaKey = "twocaptcha-secret"
api := newConfigAPITestAPI(t, fc)
@@ -107,6 +112,15 @@ func TestHandleGetConfigRedactsToken(t *testing.T) {
if env.Config.Server.Token != "" {
t.Fatalf("config token = %q, want redacted empty string", env.Config.Server.Token)
}
+ if env.Config.Security.StateEncryptionKey != nil {
+ t.Fatalf("config stateEncryptionKey = %v, want nil", env.Config.Security.StateEncryptionKey)
+ }
+ if env.Config.AutoSolver.External.CapsolverKey != "" {
+ t.Fatalf("config capsolverKey = %q, want redacted empty string", env.Config.AutoSolver.External.CapsolverKey)
+ }
+ if env.Config.AutoSolver.External.TwoCaptchaKey != "" {
+ t.Fatalf("config twoCaptchaKey = %q, want redacted empty string", env.Config.AutoSolver.External.TwoCaptchaKey)
+ }
if !env.TokenConfigured {
t.Fatal("tokenConfigured = false, want true")
}
@@ -115,6 +129,10 @@ func TestHandleGetConfigRedactsToken(t *testing.T) {
func TestHandlePutConfigPreservesExistingToken(t *testing.T) {
fc := config.DefaultFileConfig()
fc.Server.Token = "secret-token"
+ stateKey := "state-secret"
+ fc.Security.StateEncryptionKey = &stateKey
+ fc.AutoSolver.External.CapsolverKey = "capsolver-secret"
+ fc.AutoSolver.External.TwoCaptchaKey = "twocaptcha-secret"
api := newConfigAPITestAPI(t, fc)
@@ -149,11 +167,73 @@ func TestHandlePutConfigPreservesExistingToken(t *testing.T) {
if saved.Server.Token != "secret-token" {
t.Fatalf("saved token = %q, want existing token preserved", saved.Server.Token)
}
+ if saved.Security.StateEncryptionKey == nil || *saved.Security.StateEncryptionKey != stateKey {
+ t.Fatalf("saved stateEncryptionKey = %v, want existing key preserved", saved.Security.StateEncryptionKey)
+ }
+ if saved.AutoSolver.External.CapsolverKey != "capsolver-secret" {
+ t.Fatalf("saved capsolverKey = %q, want existing key preserved", saved.AutoSolver.External.CapsolverKey)
+ }
+ if saved.AutoSolver.External.TwoCaptchaKey != "twocaptcha-secret" {
+ t.Fatalf("saved twoCaptchaKey = %q, want existing key preserved", saved.AutoSolver.External.TwoCaptchaKey)
+ }
if saved.Server.Port != "9999" {
t.Fatalf("saved port = %q, want %q", saved.Server.Port, "9999")
}
}
+func TestHandlePutConfigPreservesWriteOnlySecretsFromRedactedGetPayload(t *testing.T) {
+ fc := config.DefaultFileConfig()
+ fc.Server.Token = "secret-token"
+ stateKey := "state-secret"
+ fc.Security.StateEncryptionKey = &stateKey
+ fc.AutoSolver.External.CapsolverKey = "capsolver-secret"
+ fc.AutoSolver.External.TwoCaptchaKey = "twocaptcha-secret"
+
+ api := newConfigAPITestAPI(t, fc)
+
+ getReq := httptest.NewRequest(http.MethodGet, "/api/config", nil)
+ getRes := httptest.NewRecorder()
+ api.HandleGetConfig(getRes, getReq)
+ if getRes.Code != http.StatusOK {
+ t.Fatalf("HandleGetConfig() status = %d, want %d", getRes.Code, http.StatusOK)
+ }
+
+ env := decodeConfigEnvelope(t, getRes)
+ env.Config.Server.Port = "9898"
+
+ body, err := json.Marshal(env.Config)
+ if err != nil {
+ t.Fatalf("Marshal() error = %v", err)
+ }
+
+ putReq := httptest.NewRequest(http.MethodPut, "/api/config", bytes.NewReader(body))
+ putRes := httptest.NewRecorder()
+ api.HandlePutConfig(putRes, putReq)
+ if putRes.Code != http.StatusOK {
+ t.Fatalf("HandlePutConfig() status = %d, want %d", putRes.Code, http.StatusOK)
+ }
+
+ saved, _, err := config.LoadFileConfig()
+ if err != nil {
+ t.Fatalf("LoadFileConfig() error = %v", err)
+ }
+ if saved.Server.Token != "secret-token" {
+ t.Fatalf("saved token = %q, want existing token preserved", saved.Server.Token)
+ }
+ if saved.Security.StateEncryptionKey == nil || *saved.Security.StateEncryptionKey != stateKey {
+ t.Fatalf("saved stateEncryptionKey = %v, want existing key preserved", saved.Security.StateEncryptionKey)
+ }
+ if saved.AutoSolver.External.CapsolverKey != "capsolver-secret" {
+ t.Fatalf("saved capsolverKey = %q, want existing key preserved", saved.AutoSolver.External.CapsolverKey)
+ }
+ if saved.AutoSolver.External.TwoCaptchaKey != "twocaptcha-secret" {
+ t.Fatalf("saved twoCaptchaKey = %q, want existing key preserved", saved.AutoSolver.External.TwoCaptchaKey)
+ }
+ if saved.Server.Port != "9898" {
+ t.Fatalf("saved port = %q, want %q", saved.Server.Port, "9898")
+ }
+}
+
func TestHandlePutConfigPreservesUnspecifiedAttachSettings(t *testing.T) {
fc := config.DefaultFileConfig()
fc.Server.Token = "secret-token"
@@ -257,3 +337,82 @@ func decodeConfigEnvelope(t *testing.T, w *httptest.ResponseRecorder) configEnve
}
return env
}
+
+// TestRedactTokenCoversAllSensitiveFields uses reflection to find fields that look
+// like secrets (containing "key", "token", "secret", "password", "credential" in their
+// name) and verifies they are all redacted. This test will fail if a new sensitive
+// field is added to FileConfig without updating redactToken().
+func TestRedactTokenCoversAllSensitiveFields(t *testing.T) {
+ // Populate all known sensitive fields with non-zero values
+ fc := config.DefaultFileConfig()
+ fc.Server.Token = "test-token"
+ encKey := "test-encryption-key"
+ fc.Security.StateEncryptionKey = &encKey
+ fc.AutoSolver.External.CapsolverKey = "test-capsolver-key"
+ fc.AutoSolver.External.TwoCaptchaKey = "test-twocaptcha-key"
+
+ redacted := redactToken(fc)
+
+ // Use reflection to find any sensitive fields that weren't redacted
+ var unredacted []string
+ findSensitiveFields(reflect.ValueOf(redacted), "", &unredacted)
+
+ if len(unredacted) > 0 {
+ t.Fatalf("redactToken() did not redact sensitive fields: %v\n"+
+ "Add these to redactToken() in config_api.go", unredacted)
+ }
+}
+
+// findSensitiveFields recursively scans a struct for fields with names suggesting
+// they contain secrets, and reports any that have non-zero values.
+func findSensitiveFields(v reflect.Value, path string, unredacted *[]string) {
+ if v.Kind() == reflect.Ptr {
+ if v.IsNil() {
+ return
+ }
+ v = v.Elem()
+ }
+
+ if v.Kind() != reflect.Struct {
+ return
+ }
+
+ sensitivePatterns := []string{"key", "token", "secret", "password", "credential"}
+
+ t := v.Type()
+ for i := 0; i < v.NumField(); i++ {
+ field := t.Field(i)
+ fieldPath := field.Name
+ if path != "" {
+ fieldPath = path + "." + field.Name
+ }
+
+ fieldVal := v.Field(i)
+
+ // Check if field name suggests it's sensitive
+ nameLower := strings.ToLower(field.Name)
+ isSensitive := false
+ for _, pattern := range sensitivePatterns {
+ if strings.Contains(nameLower, pattern) {
+ isSensitive = true
+ break
+ }
+ }
+
+ if isSensitive && !isZeroValue(fieldVal) {
+ *unredacted = append(*unredacted, fieldPath)
+ }
+
+ // Recurse into nested structs
+ if fieldVal.Kind() == reflect.Struct || (fieldVal.Kind() == reflect.Ptr && fieldVal.Elem().Kind() == reflect.Struct) {
+ findSensitiveFields(fieldVal, fieldPath, unredacted)
+ }
+ }
+}
+
+func isZeroValue(v reflect.Value) bool {
+ if v.Kind() == reflect.Ptr {
+ return v.IsNil()
+ }
+ return v.IsZero()
+}