Skip to content

fix(webhook): preserve custom payload string values that look like YAML - #5304

Merged
siavashs merged 1 commit into
prometheus:mainfrom
siavashs:fix/webhook/templayte/custom_payload
Jun 15, 2026
Merged

siavashs merged 1 commit into
prometheus:mainfrom
siavashs:fix/webhook/templayte/custom_payload

Conversation

@siavashs

Copy link
Copy Markdown
Contributor

The custom webhook payload feature renders a Go template and, when the output decodes into a structured value (e.g. via toJson), embeds it as real JSON. DeepCopyWithTemplate did this by recursing back into itself over the decoded value, which re-templated and re-parsed every leaf. Because JSON is a subset of YAML, a quoted leaf such as "value1:" decoded correctly on the first pass but was reinterpreted on the second, turning it into the map {"value1": null}. The same affected strings resembling numbers, booleans, null and dates.

Decode the rendered string once and normalize the result into JSON-compatible types without re-templating or re-parsing its leaves, keeping scalar values verbatim. Add regression tests at both the template and webhook levels.

Fixes #5302

Pull Request Checklist

Please check all the applicable boxes.

  • Please list all open issue(s) discussed with maintainers related to this change
    • Fixes #
  • Is this a new Receiver integration?
  • Is this a bugfix?
    • I have added tests that can reproduce the bug which pass with this bugfix applied
  • Is this a new feature?
    • I have added tests that test the new feature's functionality
  • Does this change affect performance?
    • I have provided benchmarks comparison that shows performance is improved or is not degraded
      • You can use benchstat to compare benchmarks
    • I have added new benchmarks if required or requested by maintainers
  • Is this a breaking change?
    • My changes do not break the existing cluster messages
    • My changes do not break the existing api
  • I have added/updated the required documentation
  • I have signed-off my commits
  • I will follow best practices for contributing to this project

Which user-facing changes does this PR introduce?

[BUGFIX] webhook: Keep custom `payload` string values verbatim instead of reinterpreting JSON leaves that look like YAML (e.g. values ending with a colon). #5302

The custom webhook `payload` feature renders a Go template and, when the
output decodes into a structured value (e.g. via `toJson`), embeds it as
real JSON. DeepCopyWithTemplate did this by recursing back into itself over
the decoded value, which re-templated and re-parsed every leaf. Because JSON
is a subset of YAML, a quoted leaf such as "value1:" decoded correctly on the
first pass but was reinterpreted on the second, turning it into the map
{"value1": null}. The same affected strings resembling numbers, booleans,
null and dates.

Decode the rendered string once and normalize the result into JSON-compatible
types without re-templating or re-parsing its leaves, keeping scalar values
verbatim. Add regression tests at both the template and webhook levels.

Fixes prometheus#5302

Signed-off-by: Siavash Safi <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 2f04da24-5aeb-4a10-b07d-c99b0d9e2155

📥 Commits

Reviewing files that changed from the base of the PR and between 37a5cd7 and 7aace39.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • notify/webhook/webhook_test.go
  • template/template.go
  • template/template_test.go

📝 Walkthrough

Walkthrough

The PR fixes a bug in webhook custom payload handling where strings resembling YAML (e.g., ending with colons, or looking like booleans) were being reinterpreted as YAML structures instead of remaining as strings. The core fix prevents DeepCopyWithTemplate from recursively re-parsing YAML-unmarshaled leaf scalar values, adding a normalizeYAMLValue helper to convert decoded structures to JSON-compatible Go types while preserving leaf strings unchanged.

Changes

Webhook custom payload YAML-like string preservation

Layer / File(s) Summary
Core template normalization fix
template/template.go
DeepCopyWithTemplate now uses a new normalizeYAMLValue helper to normalize YAML-unmarshaled values into JSON-compatible Go structures (arrays, string-keyed maps, unchanged scalars) instead of recursively re-templating rendered content, preventing leaf scalar strings from being reinterpreted.
Template-level regression tests
template/template_test.go
TestDeepCopyWithTemplate gains cases verifying that JSON-rendered strings with YAML-like syntax (trailing colons, numeric/boolean/null appearance) remain as strings, while actual JSON scalar types (numbers, booleans, null) preserve their correct Go types.
Webhook integration test and changelog
notify/webhook/webhook_test.go, CHANGELOG.md
TestWebhookCustomPayloadPreservesYAMLLikeStrings validates that custom templated webhook payloads preserve YAML-like label values as strings in the HTTP request body. Changelog documents the bugfix.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • prometheus/alertmanager#5130: Both PRs modify webhook custom-payload handling around template.DeepCopyWithTemplate—webhook: custom payloads allow any type #5130 deep-copies/serializes the rendered payload object, while the main PR adjusts DeepCopyWithTemplate normalization to prevent YAML/YAML-like string leaf values from being reinterpreted, with matching webhook regression tests.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main bugfix: preserving custom payload string values that resemble YAML.
Description check ✅ Passed The PR description covers the bugfix checklist item, provides technical context about the problem, includes release notes, and references the linked issue.
Linked Issues check ✅ Passed The PR addresses issue #5302 by preventing re-parsing of webhook custom payloads, preserving scalar string values and preventing YAML-like reinterpretation.
Out of Scope Changes check ✅ Passed All changes (template normalization, webhook tests, changelog) directly address the stated objective of preserving custom payload string values.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@siavashs
siavashs merged commit d3b133e into prometheus:main Jun 15, 2026
7 checks passed
@siavashs
siavashs deleted the fix/webhook/templayte/custom_payload branch June 15, 2026 10:33
@SoloJacobs SoloJacobs mentioned this pull request Aug 14, 2026
Exikle pushed a commit to Exikle/home-infra that referenced this pull request Nov 16, 2026
….1 ➔ v0.34.0) (#224)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [quay.io/prometheus/alertmanager](https://github.com/prometheus/alertmanager) | minor | `v0.33.1` → `v0.34.0` |

---

> ⚠️ **Warning**
>
> Some dependencies could not be looked up. Check the [Dependency Dashboard](issues/13) for more information.

---

### Release Notes

<details>
<summary>prometheus/alertmanager (quay.io/prometheus/alertmanager)</summary>

### [`v0.34.0`](https://github.com/prometheus/alertmanager/releases/tag/v0.34.0): 0.34.0 / 2026-08-16

[Compare Source](prometheus/alertmanager@v0.33.1...v0.34.0)

- \[CHANGE] notify: The `reason` label on `alertmanager_notifications_failed_total` now distinguishes `authError` (HTTP 401/403) and `rateLimited` (HTTP 429) from the generic `clientError`. Dashboards/alerts matching `reason="clientError"` for these codes must be updated. [#&#8203;5332](prometheus/alertmanager#5332)
- \[FEATURE] Add optional templatable labels to alert routes. [#&#8203;5328](prometheus/alertmanager#5328)
- \[FEATURE] eventrecorder: Add inhibit rule names to `inhibition_muted_alert` events. [#&#8203;5315](prometheus/alertmanager#5315)
- \[FEATURE] eventrecorder: Add stdout output type. [#&#8203;5311](prometheus/alertmanager#5311)
- \[FEATURE] silences: Add active, expired, and pending boolean filter parameters to GET /api/v2/silences to allow filtering silences by state server-side. [#&#8203;5406](prometheus/alertmanager#5406)
- \[FEATURE] sns: Add aws `external_id` support in sigv4 configuration. [#&#8203;5157](prometheus/alertmanager#5157)
- \[FEATURE] template: Add `toDate` and `mustToDate` functions. [#&#8203;5327](prometheus/alertmanager#5327)
- \[ENHANCEMENT] doc: Add AlertmanagerClusterFailedPeers alertmanager-mixin. [#&#8203;5301](prometheus/alertmanager#5301)
- \[ENHANCEMENT] doc: Add description for Rocketchat parameters in global config. [#&#8203;5181](prometheus/alertmanager#5181)
- \[ENHANCEMENT] doc: Add top level tracing configuration key. [#&#8203;5314](prometheus/alertmanager#5314)
- \[ENHANCEMENT] doc: Fix Alertmanager port in amtool config routes example. [#&#8203;5312](prometheus/alertmanager#5312)
- \[ENHANCEMENT] eventrecorder: Add optional webhook batching. [#&#8203;5392](prometheus/alertmanager#5392)
- \[ENHANCEMENT] notify: The discord and webex integrations now report a failure `reason` on `alertmanager_notifications_failed_total`. [#&#8203;5332](prometheus/alertmanager#5332)
- \[ENHANCEMENT] ui: Improve responsiveness of UI when loading thousands of alerts. [#&#8203;5357](prometheus/alertmanager#5357)
- \[BUGFIX] eventrecorder: Fixed a minor performance regression when the event recorder is enabled. [#&#8203;5307](prometheus/alertmanager#5307)
- \[BUGFIX] msteamsv2: Inherit global `proxy_url` into partial `http_config`. [#&#8203;5379](prometheus/alertmanager#5379)
- \[BUGFIX] webhook: Keep custom `payload` string values verbatim instead of reinterpreting JSON leaves that look like YAML (e.g. values ending with a colon). [#&#8203;5304](prometheus/alertmanager#5304)

</details>

---

### Configuration

📅 **Schedule**: (in timezone America/Toronto)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4zMC40IiwidXBkYXRlZEluVmVyIjoiNDQuMzIuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsicHJpb3JpdHkvbWVkaXVtIiwicmVub3ZhdGUvY29udGFpbmVyIiwidHlwZS9taW5vciJdfQ==-->

Reviewed-on: https://git.dcunha.io/Exikle/frostlink/pulls/224
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parser of custom payload of webhook receiver has strange behavior

2 participants