Skip to content

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

fix(dashboard): refuse a PUT /api/config body with unrecognized top-level keys so the GET envelope round-trip fails loudly instead of discarding every edit (PIN-278)

Luigi Agosti371c6344cc7f
diff --git a/docs/endpoints.md b/docs/endpoints.md
index 41504965..b5ddd511 100644
--- a/docs/endpoints.md
+++ b/docs/endpoints.md
@@ -40,6 +40,7 @@ PUT /api/config
Notes:
- `server.token` is treated as write-only by `PUT /api/config`
+- `PUT /api/config` expects the inner config object, not the envelope `GET /api/config` returns; a body carrying an unrecognized top-level key (such as the envelope's own `config`) is refused with a `400 unrecognized_config_keys` rather than silently applying nothing
- auth routes are for the dashboard session flow
## Dashboard Events And Agents
diff --git a/internal/dashboard/config_api.go b/internal/dashboard/config_api.go
index fde4afda..cd21e244 100644
--- a/internal/dashboard/config_api.go
+++ b/internal/dashboard/config_api.go
@@ -183,6 +183,13 @@ func (c *ConfigAPI) parseConfigUpdate(w http.ResponseWriter, r *http.Request, cu
return config.FileConfig{}, false
}
+ if unknown := config.UnknownFileConfigKeys(body); len(unknown) > 0 {
+ httpx.ErrorCode(w, 400, "unrecognized_config_keys", "PUT the inner config object, not the GET envelope", false, map[string]any{
+ "unrecognizedKeys": unknown,
+ })
+ return config.FileConfig{}, false
+ }
+
normalized := *current
if err := json.NewDecoder(bytes.NewReader(body)).Decode(&normalized); err != nil {
httpx.ErrorCode(w, 400, "bad_config_json", "invalid config payload", false, nil)
diff --git a/internal/dashboard/config_api_test.go b/internal/dashboard/config_api_test.go
index 5606dd2f..85bef206 100644
--- a/internal/dashboard/config_api_test.go
+++ b/internal/dashboard/config_api_test.go
@@ -366,6 +366,87 @@ func TestHandlePutConfigRejectsWriteOnlyTokenField(t *testing.T) {
}
}
+func TestHandlePutConfigRefusesGetEnvelopeAndAppliesNothing(t *testing.T) {
+ fc := config.DefaultFileConfig()
+ fc.Server.Token = "secret-token"
+ api := newConfigAPITestAPI(t, fc)
+
+ getReq := httptest.NewRequest(http.MethodGet, "/api/config", nil)
+ getRes := httptest.NewRecorder()
+ api.HandleGetConfig(getRes, getReq)
+
+ var envelope map[string]any
+ if err := json.Unmarshal(getRes.Body.Bytes(), &envelope); err != nil {
+ t.Fatalf("Unmarshal GET payload: %v", err)
+ }
+ inner := envelope["config"].(map[string]any)
+ inner["timeouts"].(map[string]any)["actionSec"] = 31
+ body, err := json.Marshal(envelope)
+ if err != nil {
+ t.Fatalf("Marshal PUT body: %v", err)
+ }
+
+ req := httptest.NewRequest(http.MethodPut, "/api/config", bytes.NewReader(body))
+ w := httptest.NewRecorder()
+ api.HandlePutConfig(w, req)
+
+ if w.Code != http.StatusBadRequest {
+ t.Fatalf("HandlePutConfig() status = %d, want %d; body=%s", w.Code, http.StatusBadRequest, w.Body.String())
+ }
+ if !strings.Contains(w.Body.String(), "unrecognized_config_keys") {
+ t.Fatalf("response = %q, want unrecognized_config_keys error", w.Body.String())
+ }
+
+ saved, _, err := config.LoadFileConfig()
+ if err != nil {
+ t.Fatalf("LoadFileConfig() error = %v", err)
+ }
+ if saved.Timeouts.ActionSec != 30 {
+ t.Fatalf("saved timeouts.actionSec = %d, want unchanged 30", saved.Timeouts.ActionSec)
+ }
+}
+
+func TestHandlePutConfigAppliesTheInnerObject(t *testing.T) {
+ fc := config.DefaultFileConfig()
+ fc.Server.Token = "secret-token"
+ api := newConfigAPITestAPI(t, fc)
+
+ body := []byte(`{"timeouts":{"actionSec":45}}`)
+ req := httptest.NewRequest(http.MethodPut, "/api/config", bytes.NewReader(body))
+ w := httptest.NewRecorder()
+ api.HandlePutConfig(w, req)
+
+ if w.Code != http.StatusOK {
+ t.Fatalf("HandlePutConfig() status = %d, want %d; body=%s", w.Code, http.StatusOK, w.Body.String())
+ }
+
+ saved, _, err := config.LoadFileConfig()
+ if err != nil {
+ t.Fatalf("LoadFileConfig() error = %v", err)
+ }
+ if saved.Timeouts.ActionSec != 45 {
+ t.Fatalf("saved timeouts.actionSec = %d, want 45", saved.Timeouts.ActionSec)
+ }
+}
+
+func TestHandlePutConfigRefusesAnyUnrecognizedTopLevelKey(t *testing.T) {
+ fc := config.DefaultFileConfig()
+ fc.Server.Token = "secret-token"
+ api := newConfigAPITestAPI(t, fc)
+
+ body := []byte(`{"timeoutz":{"actionSec":45}}`)
+ req := httptest.NewRequest(http.MethodPut, "/api/config", bytes.NewReader(body))
+ w := httptest.NewRecorder()
+ api.HandlePutConfig(w, req)
+
+ if w.Code != http.StatusBadRequest {
+ t.Fatalf("HandlePutConfig() status = %d, want %d; body=%s", w.Code, http.StatusBadRequest, w.Body.String())
+ }
+ if !strings.Contains(w.Body.String(), "timeoutz") {
+ t.Fatalf("response = %q, want the unrecognized key named", w.Body.String())
+ }
+}
+
func TestHandlePutConfigRequiresElevationForProxyChangeWithDashboardCookie(t *testing.T) {
fc := config.DefaultFileConfig()
fc.Server.Token = "secret-token"