From 018fbe204d721991daabb7a188e1d86e6886df23 Mon Sep 17 00:00:00 2001 From: Sanaei Date: Thu, 26 Nov 2026 11:56:24 +0330 Subject: [PATCH] fix(inbounds): refuse a null settings payload instead of panicking An inbound save whose settings is the JSON value null reached keepStoredClients, where null decodes into a nil map without an error. Putting the stored client list back into that map panicked inside the traffic writer, so the caller got "traffic writer panic: assignment to entry in nil map" and the panel logged a stack trace. A null payload is now left as it is, and the client validation that runs next refuses it with the same "inbound settings is empty" every other empty settings value gets. --- .../web/service/inbound_settings_commit.go | 3 ++- .../service/inbound_update_stale_form_test.go | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/internal/web/service/inbound_settings_commit.go b/internal/web/service/inbound_settings_commit.go index 2c902f2ec..98d4bb64a 100644 --- a/internal/web/service/inbound_settings_commit.go +++ b/internal/web/service/inbound_settings_commit.go @@ -145,7 +145,8 @@ func mergeClientLists(base, ours, current []any) []any { // payload: clients change through the client endpoints, never this form. func keepStoredClients(payload, stored string) string { var payloadM, storedM map[string]any - if json.Unmarshal([]byte(payload), &payloadM) != nil || json.Unmarshal([]byte(stored), &storedM) != nil { + // A JSON null decodes into a nil map without an error; client validation refuses it next. + if json.Unmarshal([]byte(payload), &payloadM) != nil || json.Unmarshal([]byte(stored), &storedM) != nil || payloadM == nil { return payload } storedClients, has := storedM["clients"] diff --git a/internal/web/service/inbound_update_stale_form_test.go b/internal/web/service/inbound_update_stale_form_test.go index 136270107..716ddf0d1 100644 --- a/internal/web/service/inbound_update_stale_form_test.go +++ b/internal/web/service/inbound_update_stale_form_test.go @@ -1,6 +1,7 @@ package service import ( + "strings" "testing" "time" @@ -168,3 +169,20 @@ func TestInboundFormSaveKeepsEnableToggledWhileOpen(t *testing.T) { t.Fatalf("after save: enable=%v remark=%q, want disabled and edited", saved.Enable, saved.Remark) } } + +// A null settings payload is not an object the stored clients can be put back +// into; the save must refuse it like any other empty settings. +func TestInboundFormSaveRefusesNullSettings(t *testing.T) { + setupBulkDB(t) + ib := seedRenewableNeighbour(t, 23209, nil) + form := *ib + form.Settings = "null" + + _, _, err := (&InboundService{}).UpdateInbound(&form) + if err == nil || strings.TrimSpace(err.Error()) != "inbound settings is empty" { + t.Fatalf("UpdateInbound err = %v, want %q", err, "inbound settings is empty") + } + if _, ok := settingsClient(t, ib.Id, "y@stale"); !ok { + t.Fatal("the refused save dropped a stored client") + } +}