AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary
Python ai-promptsai-skillblueskyclaudeclaude-codeclawhubdeep-researchhackernewsinstagramopenclawpolymarketrecencyredditresearchsocial-mediatiktoktrendstwitterweb-searchyoutube
fix(digg): reject non-http xUrl to close stored-XSS in HTML report (#434)
Ilia Alshanetskybe8438459ad5
diff --git a/skills/last30days/scripts/lib/digg.py b/skills/last30days/scripts/lib/digg.pyindex 48844775..1595331d 100644--- a/skills/last30days/scripts/lib/digg.py+++ b/skills/last30days/scripts/lib/digg.py@@ -22,6 +22,7 @@ import jsonimport shutilfrom datetime import datetime, timedelta, timezonefrom typing import Any, Dict, List, Optional+from urllib.parse import urlparsefrom . import log, subprocfrom .relevance import token_overlap_relevance@@ -296,6 +297,20 @@ def parse_digg_response(return items+def _is_safe_http_url(url: str) -> bool:+ """True iff ``url`` parses with an http or https scheme.++ Used to reject upstream-supplied post URLs whose scheme would be+ dangerous in a rendered ``<a href>`` (``javascript:``, ``data:``,+ ``file:``, ``vbscript:``, ``about:``).+ """+ try:+ scheme = urlparse(url).scheme.lower()+ except ValueError:+ return False+ return scheme in ("http", "https")++def _parse_post(raw_post: Dict[str, Any]) -> Optional[Dict[str, Any]]:"""Reduce a digg post payload into the small dict render uses.@@ -316,6 +331,17 @@ def _parse_post(raw_post: Dict[str, Any]) -> Optional[Dict[str, Any]]:x_url = str(raw_post.get("xUrl") or "").strip()if not x_url:return None+ if not _is_safe_http_url(x_url):+ # Security-class drop: an upstream-supplied URL with a dangerous+ # scheme. Force tty_only=False so the rejection is visible in+ # non-interactive runs (Claude Code), which is the actual attack+ # surface — the default tty_only=True would suppress it there.+ log.source_log(+ "Digg",+ f"dropped post with unsafe xUrl scheme: {x_url!r}",+ tty_only=False,+ )+ return Nonereturn {"username": username,"display_name": str(author.get("display_name") or "").strip() or username,diff --git a/tests/test_digg.py b/tests/test_digg.pyindex fd9c6732..e17d90df 100644--- a/tests/test_digg.py+++ b/tests/test_digg.py@@ -206,6 +206,43 @@ def test_parse_post_drops_missing_body_or_handle_or_url():assert digg._parse_post({"author": {"username": "x"}, "body": "txt", "xUrl": ""}) is Noneassert digg._parse_post(None) is None # type: ignore[arg-type]++def test_parse_post_drops_non_http_scheme_xurl():+ """Any non-http(s) scheme on xUrl yields no post.++ A malicious Digg API response (or compromised upstream) could set xUrl to+ javascript:, data:text/html;..., file:, vbscript:, etc. The HTML report+ renders the xUrl into an <a href> attribute, so any non-web scheme is a+ stored-XSS or local-file vector when the user clicks the attribution.+ """+ for bad_url in (+ "javascript:alert(1)",+ "data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg==",+ "vbscript:msgbox(1)",+ "file:///etc/passwd",+ "about:blank",+ ):+ out = digg._parse_post(_post(x_url=bad_url))+ assert out is None, f"expected non-http xUrl to be dropped, got: {out}"++ # http and https remain accepted.+ assert digg._parse_post(_post(x_url="https://x.com/a/status/1")) is not None+ assert digg._parse_post(_post(x_url="http://x.com/a/status/1")) is not None+++def test_parse_post_logs_unsafe_xurl_rejection_even_in_non_tty(capsys):+ """Security-class drops must be observable in non-interactive runs.++ The default ``log.source_log`` path is TTY-gated; without forcing+ ``tty_only=False`` the rejection is invisible in Claude Code runs,+ which is exactly the attack surface. Guard against silent regression.+ """+ digg._parse_post(_post(x_url="javascript:alert(1)"))+ err = capsys.readouterr().err+ assert "[Digg] dropped post with unsafe xUrl scheme" in err+ assert "javascript:alert(1)" in err++# === _run_cli / search_digg with stubbed subprocess ===