-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat(docs): add gotify example using webhook custom payload #5408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| # Copyright The Prometheus Authors | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # This is an example of how to send notifications to a Gotify | ||
| # (https://gotify.net) server using the generic webhook receiver with a | ||
| # custom payload, instead of a dedicated Gotify integration. | ||
| # | ||
| # Gotify's push message API expects a JSON body with "title", "message" and | ||
| # "priority" fields, plus an optional "extras" object. See | ||
| # https://gotify.net/docs/pushmsg for the full list of supported fields. | ||
| # | ||
| # Authentication is done via bearer token as described in | ||
| # https://gotify.net/api-docs | ||
| receivers: | ||
| - name: gotify | ||
| webhook_configs: | ||
| - url: 'https://gotify.example.com/message' | ||
| send_resolved: true | ||
| http_config: | ||
| authorization: | ||
| credentials_file: /etc/alertmanager/secrets/gotify-secret/token | ||
| payload: | ||
| title: '{{ .Status | toUpper }} {{ .CommonLabels.alertname }}{{ with .CommonLabels.instance }} {{ . }}{{ end }}' | ||
| priority: '{{ if eq .Status "firing" }}5{{ else }}0{{ end }}' | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| extras: | ||
| "client::display": | ||
| contentType: "text/markdown" | ||
| message: | | ||
| {{ if gt (len .Alerts.Firing) 0 }} | ||
| {{ range .Alerts.Firing }} | ||
| **{{ .Annotations.summary }}** | ||
|
|
||
| **Instance:** `{{ .Labels.instance }}` | ||
| **Since:** {{ .StartsAt }} | ||
| **Source:** [Prometheus]({{ .GeneratorURL }}) | ||
| {{ end }} | ||
| {{ end }} | ||
| {{ if gt (len .Alerts.Resolved) 0 }} | ||
| {{ range .Alerts.Resolved }} | ||
| **{{ .Annotations.summary }}** | ||
|
|
||
| **Instance:** `{{ .Labels.instance }}` | ||
| **Resolved:** {{ .EndsAt }} | ||
| **Source:** [Prometheus]({{ .GeneratorURL }}) | ||
| {{ end }} | ||
| {{ end }} | ||
|
|
||
| [View in Alertmanager]({{ .ExternalURL }}) | ||
|
Comment on lines
+35
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -eu
file=$(fd -t f '^gotify\.yml$' . | head -n 1)
printf '%s\n' "FILE=$file"
cat -n "$file" | sed -n '1,100p'
printf '%s\n' '--- Gotify-related references ---'
rg -n -i 'gotify|text/markdown|client::display|msgextras' . -g '!node_modules' -g '!dist' -g '!build' | head -n 200Repository: prometheus/alertmanager Length of output: 5274 🌐 Web query:
💡 Result: In Gotify, the use of text/markdown in the client::display extra is documented to pose security risks related to information disclosure, specifically involving remote image rendering [1][2]. When a message is set to text/markdown, Gotify clients (such as the Web UI or mobile applications) may render markdown content, including images specified via the syntax [1][2]. The primary security concerns are as follows: 1. Remote Image Tracking: Automatically downloading remote images when a message is viewed can be exploited to collect information about the user, similar to how remote content loading is restricted in email clients [1][2]. 2. Malicious Interpolation: If any part of the message content is interpolated from a malicious or untrusted external source, an attacker could inject malformed markdown. This can lead to information disclosure or other unintended behaviors when the client attempts to render the malicious content [1][2][3]. To mitigate these risks, the official Gotify documentation recommends using text/plain (the default) whenever possible, especially when the message content is generated from external sources, such as script outputs [1][2]. By using text/plain, the client renders the message as plain text, avoiding the automatic parsing of markdown and the associated risks of remote image loading and malformed markdown injection [1][2]. Citations:
🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- Related documentation ---'
cat -n docs/notification_examples.md | sed -n '155,185p'
printf '%s\n' '--- Template and escaping references ---'
rg -n -i 'text/template|html/template|escaping|annotations|labels.*template|template.*annotations' docs template *.go */*.go 2>/dev/null | head -n 200Repository: prometheus/alertmanager Length of output: 20749 🏁 Script executed: python3 - <<'PY'
from pathlib import Path
import re
path = Path("examples/webhook/gotify.yml")
text = path.read_text()
body = text.split(" message: |", 1)[1]
fields = re.findall(r"\{\{\s*([^{}]+?)\s*\}\}", body)
print("Interpolated fields:")
for field in fields:
print("-", field.strip())
# Demonstrate that the template places alert-controlled annotation data
# directly inside Markdown without escaping.
rendered = body.replace("{{ .Annotations.summary }}", "ok ")
print("\nInjected Markdown survives:")
for line in rendered.splitlines():
if "tracking" in line:
print(line.strip())
PYRepository: prometheus/alertmanager Length of output: 602 Use If alert data can be controlled by untrusted workloads or tenants, interpolated Markdown can add remote images that Gotify clients request when users view the message. Use 🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: prometheus/alertmanager
Length of output: 19207
🏁 Script executed:
Repository: prometheus/alertmanager
Length of output: 32813
🏁 Script executed:
Repository: prometheus/alertmanager
Length of output: 12255
Set a finite webhook timeout.
The omitted
timeoutdefaults to0s, so no webhook-specific timeout applies. Alertmanager still cancels the notification pipeline atgroup_interval(default5m). Add a deployment-appropriate timeout belowgroup_intervalto fail slow requests sooner and allow retries.🤖 Prompt for AI Agents