mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-11-29 09:10:58 +01:00
Validate webhook IDs directly without legacy hash branch (#5221)
## Summary - Validate duplicate trimmed webhook IDs directly in `ValidateWebhookInventory` instead of calling `webhookInventoryIdentity` after already skipping empty IDs. - Add unit coverage in `TestValidateWebhookInventory` for trimmed duplicate detection and legacy ID-less webhook compatibility. ## Why `ValidateWebhookInventory` skips entries with an empty trimmed ID before checking duplicates, so `webhookInventoryIdentity` always returned the trimmed ID and never reached its legacy SHA-256 fallback. Calling `webhookInventoryIdentity` still caused CodeQL (`go/weak-sensitive-data-hashing`, alert #368) to trace decrypted configuration imports from `decryptWithPassphrase` into `hashDeliveryDestination` (`internal/notifications/notification_dispatch.go:374`). ## Verification - `go test -v -count=1 -run 'TestValidateWebhookInventory|TestNotificationLegacyAnonymousWebhookInventoryRetainsAuthority' ./internal/notifications` - `go test -count=1 -run 'TestExport|TestImport' ./internal/config`
This commit is contained in:
@@ -627,14 +627,14 @@ func webhookInventoryIdentity(hook WebhookConfig) string {
|
||||
func ValidateWebhookInventory(webhooks []WebhookConfig) error {
|
||||
seen := make(map[string]bool, len(webhooks))
|
||||
for _, hook := range webhooks {
|
||||
if strings.TrimSpace(hook.ID) == "" {
|
||||
id := strings.TrimSpace(hook.ID)
|
||||
if id == "" {
|
||||
continue
|
||||
}
|
||||
identity := webhookInventoryIdentity(hook)
|
||||
if seen[identity] {
|
||||
if seen[id] {
|
||||
return fmt.Errorf("duplicate webhook identity in destination inventory")
|
||||
}
|
||||
seen[identity] = true
|
||||
seen[id] = true
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -847,6 +847,19 @@ func TestNotificationLegacyAnonymousWebhookInventoryRetainsAuthority(t *testing.
|
||||
require.Error(t, ValidateWebhookInventory([]WebhookConfig{{ID: "same"}, {ID: "same"}}))
|
||||
}
|
||||
|
||||
func TestValidateWebhookInventory(t *testing.T) {
|
||||
require.NoError(t, ValidateWebhookInventory([]WebhookConfig{
|
||||
{URL: "http://127.0.0.1:9/first"},
|
||||
{ID: " ", URL: "http://127.0.0.1:9/second"},
|
||||
{ID: "ops-a", URL: "http://127.0.0.1:9/a"},
|
||||
{ID: "ops-b", URL: "http://127.0.0.1:9/b"},
|
||||
}))
|
||||
require.Error(t, ValidateWebhookInventory([]WebhookConfig{
|
||||
{ID: "ops-a", URL: "http://127.0.0.1:9/a"},
|
||||
{ID: " ops-a ", URL: "http://127.0.0.1:9/b"},
|
||||
}))
|
||||
}
|
||||
|
||||
func TestNotificationRelayReceiverUpgradePreservesOnlyKnownReceiverScope(t *testing.T) {
|
||||
cases := []struct {
|
||||
id string
|
||||
|
||||
Reference in New Issue
Block a user