From 34dfb8a3d30e10eeca0aaa3fd5a85f8afd04d70b Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Wed, 28 Oct 2026 00:36:33 +1100 Subject: [PATCH] fix(controlplane): reject userinfo and query in notify_webhook A webhook URL with embedded credentials or a query string can leak secrets through logs, proxies and referrer headers. The task policy validator now refuses both. --- .../controlplanestore/task_policy.go | 6 ++++ .../controlplanestore/task_policy_test.go | 28 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/internal/infrastructure/controlplanestore/task_policy.go b/internal/infrastructure/controlplanestore/task_policy.go index c5360f823..a43ad87da 100644 --- a/internal/infrastructure/controlplanestore/task_policy.go +++ b/internal/infrastructure/controlplanestore/task_policy.go @@ -28,6 +28,12 @@ func taskPolicyDefinition() Definition { if err != nil || parsed.Host == "" || (parsed.Scheme != "http" && parsed.Scheme != "https") { return fmt.Errorf("notify_webhook must be an HTTP or HTTPS URL") } + if parsed.User != nil { + return fmt.Errorf("notify_webhook must not carry credentials in the URL") + } + if parsed.RawQuery != "" || parsed.ForceQuery { + return fmt.Errorf("notify_webhook must not carry a query string") + } } if !alert.Severity(doc.NotifyMinSeverity).Valid() && doc.NotifyMinSeverity != "" { return fmt.Errorf("notify_min_severity must be info, warning or action") diff --git a/internal/infrastructure/controlplanestore/task_policy_test.go b/internal/infrastructure/controlplanestore/task_policy_test.go index 0109d83b8..99431ea00 100644 --- a/internal/infrastructure/controlplanestore/task_policy_test.go +++ b/internal/infrastructure/controlplanestore/task_policy_test.go @@ -2,11 +2,39 @@ package controlplanestore import ( "errors" + "fmt" "testing" "github.com/samcharles93/archie-core/internal/domain/storecontract" ) +func TestTaskPolicyNotifyWebhookValidation(t *testing.T) { + tests := []struct { + name string + webhook string + refused bool + }{ + {"empty disables delivery", "", false}, + {"plain https URL", "https://hooks.example.com/services/abc", false}, + {"plain http URL", "http://hooks.example.com/hook", false}, + {"credentials in the URL", "https://user:pass@hooks.example.com/hook", true}, + {"userinfo without password", "https://user@hooks.example.com/hook", true}, + {"query string", "https://hooks.example.com/hook?token=secret", true}, + {"bare question mark", "https://hooks.example.com/hook?", true}, + {"non-http scheme", "ftp://hooks.example.com/hook", true}, + {"no host", "https:///hook", true}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + doc := fmt.Sprintf(`{"notify_webhook":%q}`, tt.webhook) + err := taskPolicyDefinition().Validate([]byte(doc)) + if refused := err != nil; refused != tt.refused { + t.Fatalf("refused = %v, want %v (err %v)", refused, tt.refused, err) + } + }) + } +} + func TestTaskPolicyNamesNoInstanceSecretForAnotherOrg(t *testing.T) { const signed = `{"notify_webhook":"https://example.com/hook","notify_secret":{"engine":"env","key":"INSTANCE_KEY"}}` const unsigned = `{"notify_webhook":"https://example.com/hook"}`