Discord alert backend: send 'valid' URLs only

Fix #280
This commit is contained in:
Klaas van Schelven
2025-11-25 20:47:07 +01:00
parent ae80403c7c
commit 4e71f4f04c

View File

@@ -1,3 +1,4 @@
from urllib.parse import urlparse
import json
import requests
from django.utils import timezone
@@ -12,6 +13,16 @@ from bugsink.transaction import immediate_atomic
from issues.models import Issue
def url_valid_according_to_discord(url):
# See https://github.com/bugsink/bugsink/issues/280 for "according to Discord"
parsed = urlparse(url)
return (
parsed.scheme in ("http", "https")
and parsed.hostname is not None
and "." in parsed.hostname
)
class DiscordConfigForm(forms.Form):
# NOTE: As of yet this code isn't plugged into the UI (because it requires dynamic loading of the config-specific
# form)
@@ -139,12 +150,14 @@ def discord_backend_send_alert(
embed = {
"title": issue_title,
"url": issue_url,
"description": f"{alert_reason} issue",
"color": color,
"fields": [{"name": "Project", "value": issue.project.name, "inline": True}],
}
if url_valid_according_to_discord(issue_url):
embed["url"] = issue_url
if unmute_reason:
embed["fields"].append(
{"name": "Unmute Reason", "value": unmute_reason, "inline": False}