Skip to content

AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary

fix(watchlist): validate webhook scheme and match Slack host exactly

Ilia Alshanetskyae65f9aad1e0
diff --git a/skills/last30days/scripts/watchlist.py b/skills/last30days/scripts/watchlist.py
index bf2903ad..e855383a 100644
--- a/skills/last30days/scripts/watchlist.py
+++ b/skills/last30days/scripts/watchlist.py
@@ -8,6 +8,7 @@ import json
import subprocess
import sys
import time
+import urllib.parse
from pathlib import Path
SCRIPT_DIR = Path(__file__).parent.resolve()
@@ -28,10 +29,22 @@ def _deliver_findings(topic_name: str, counts: dict) -> None:
mode = store.get_setting("delivery_mode", "announce")
message = _format_delivery_message(topic_name, counts, mode)
+ # Require https before routing. The old "hooks.slack.com" in channel
+ # substring test ran before any scheme check, so a channel like
+ # http://evil.example/hooks.slack.com was treated as Slack and POSTed in
+ # cleartext to the wrong host. Match Slack on the exact hostname instead.
+ parsed = urllib.parse.urlparse(channel)
+ if parsed.scheme != "https":
+ print(
+ f"Delivery skipped: delivery_channel must be an https:// URL, got {channel!r}",
+ file=sys.stderr,
+ )
+ return
+
try:
- if "hooks.slack.com" in channel:
+ if parsed.hostname == "hooks.slack.com":
_send_slack_webhook(channel, message)
- elif channel.startswith("https://"):
+ else:
_send_generic_webhook(channel, message)
except Exception as e:
# Don't fail the research run if delivery fails
diff --git a/tests/test_watchlist_delivery.py b/tests/test_watchlist_delivery.py
index 3d344088..7e6a2249 100644
--- a/tests/test_watchlist_delivery.py
+++ b/tests/test_watchlist_delivery.py
@@ -225,6 +225,42 @@ def test_deliver_findings_handles_failure_gracefully(mock_post, mock_get_setting
@patch('watchlist.http.post')
+def test_deliver_findings_rejects_non_https_slack_substring(mock_post, mock_get_setting, capsys):
+ """A non-https channel that merely contains 'hooks.slack.com' must not be
+ sent. The old substring match POSTed it in cleartext to whatever host the
+ URL actually named."""
+ mock_get_setting.side_effect = lambda key, default="": {
+ "delivery_channel": "http://evil.example/hooks.slack.com",
+ "delivery_mode": "announce",
+ }.get(key, default)
+
+ watchlist._deliver_findings("Test Topic", {"new": 5, "updated": 2})
+
+ assert not mock_post.called
+ assert "https://" in capsys.readouterr().err
+
+@patch('watchlist.store.get_setting')
+@patch('watchlist.http.post')
+
+
+def test_deliver_findings_slack_match_is_exact_host(mock_post, mock_get_setting):
+ """An https URL with 'hooks.slack.com' only in the path routes as generic,
+ not Slack — the match is on the exact hostname, not a substring."""
+ mock_get_setting.side_effect = lambda key, default="": {
+ "delivery_channel": "https://webhook.example.com/hooks.slack.com/x",
+ "delivery_mode": "announce",
+ }.get(key, default)
+
+ watchlist._deliver_findings("Test Topic", {"new": 5, "updated": 2})
+
+ json_data = mock_post.call_args[1]["json_data"]
+ assert "message" in json_data # generic payload shape
+ assert "text" not in json_data # not the Slack {"text": ...} shape
+
+@patch('watchlist.store.get_setting')
+@patch('watchlist.http.post')
+
+
def test_deliver_findings_respects_delivery_mode(mock_post, mock_get_setting):
"""Test that different delivery modes produce different messages."""
mock_get_setting.side_effect = lambda key, default="": {