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.
This commit is contained in:
sam committed 2026-10-28 00:36:33 +11:00
1 parent 67c87bab4b
commit 34dfb8a3d3
2 files changed
+34

No files matched your search

@@ -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")
@@ -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"}`