Free, open source blog writer for Claude Code. Researches current sources, writes answer-first posts for Google and AI answers, has an independent reviewer score each one out of 100 and ships only after five delivery gates. 32 skills, 30 /blog commands, 5 agents. Active development at AI-Marketing-Hub/claude-blog; public releases ship here.
Python agent-skillsaiai-citationsai-contentai-marketingai-marketing-hubblogblog-writingclaude-codeclaude-code-skillclaude-pluginclaude-skillcontent-creationcontent-optimizationcontent-strategyeeatgeomultilingualopen-sourceseo
fix(security): refuse redirects + tighten scheme check in Gate 5 (VULN-804+VULN-002)
Danielf9ff6eeab19c
diff --git a/scripts/blog_preflight.py b/scripts/blog_preflight.pyindex b88b0ce..e5564ae 100644--- a/scripts/blog_preflight.py+++ b/scripts/blog_preflight.py@@ -457,10 +457,34 @@ class _MetaParser(HTMLParser):self.article_text_chars += len(re.findall(r"\b\w+\b", data))+class _PreflightNoRedirectHandler(urllib.request.HTTPRedirectHandler):+ """Refuse automatic redirect-following in Gate 5 link checks (VULN-804).++ Default urllib follows 30x silently; a draft containing a redirect+ chain via attacker.example -> 169.254.169.254 would let preflight+ probe internal hosts. Refuse on the first hop; treat as broken link.+ """+ def http_error_301(self, req, fp, code, msg, headers): # noqa: D401+ return None+ http_error_302 = http_error_301+ http_error_303 = http_error_301+ http_error_307 = http_error_301+ http_error_308 = http_error_301+++_PREFLIGHT_NO_REDIRECT_OPENER = urllib.request.build_opener(_PreflightNoRedirectHandler())++def _http_head(url: str) -> int:+ """HEAD request that refuses to follow redirects (VULN-804)."""+ # VULN-002 (v1.9.1): explicit scheme check inside _http_head as+ # defense-in-depth. The upstream call site is supposed to filter+ # already, but matching the policy here closes the gap.+ if not url.startswith(("http://", "https://")):+ return 0try:req = urllib.request.Request(url, method="HEAD", headers={"User-Agent": USER_AGENT})- with urllib.request.urlopen(req, timeout=HEAD_TIMEOUT) as resp:+ with _PREFLIGHT_NO_REDIRECT_OPENER.open(req, timeout=HEAD_TIMEOUT) as resp:return resp.statusexcept Exception:return 0@@ -500,7 +524,7 @@ def gate_5_asset_link_integrity(draft_dir: Path) -> dict:# og:image specifically must resolve to a local hero.<ext> when canonical points to a hostif parser.og_image:- if parser.og_image.startswith("http"):+ if parser.og_image.startswith(("http://", "https://")):hero_files = list(draft_dir.glob("hero.*"))hero_files = [h for h in hero_files if h.suffix.lower() in {".png", ".jpg", ".jpeg", ".webp"}]if not hero_files:diff --git a/tests/test_preflight_http_head_no_redirect.py b/tests/test_preflight_http_head_no_redirect.pynew file mode 100644index 0000000..b87faac--- /dev/null+++ b/tests/test_preflight_http_head_no_redirect.py@@ -0,0 +1,69 @@+"""Gate 5 _http_head must not follow redirects (VULN-804, v1.9.1).++A draft containing <a href="http://attacker.example/?to=internal-host">+should not turn preflight into an unauthenticated outbound proxy for+the attacker. urllib's default behavior follows 30x redirects; the+no-redirect opener in this fix refuses on the first hop.+"""+from __future__ import annotations++import importlib.util+import sys+from pathlib import Path++import pytest++ROOT = Path(__file__).resolve().parent.parent+PREFLIGHT = ROOT / "scripts" / "blog_preflight.py"++[email protected](scope="module")+def preflight_module():+ spec = importlib.util.spec_from_file_location("blog_preflight_m", PREFLIGHT)+ mod = importlib.util.module_from_spec(spec)+ sys.modules["blog_preflight_m"] = mod+ spec.loader.exec_module(mod)+ return mod+++def test_http_head_non_http_scheme_returns_zero(preflight_module):+ """VULN-002 defense-in-depth: file:// / data:// / etc. return 0."""+ for url in (+ "file:///etc/passwd",+ "ftp://example.com/",+ "javascript:alert(1)",+ "data:text/plain;base64,YWJj",+ "",+ "no-scheme",+ ):+ assert preflight_module._http_head(url) == 0, (+ f"expected 0 for non-http(s) URL: {url!r}"+ )+++def test_http_head_uses_no_redirect_opener(preflight_module):+ """The opener used for HEAD must refuse redirects."""+ opener = preflight_module._PREFLIGHT_NO_REDIRECT_OPENER+ # Walk the handler chain; one of them must be the no-redirect class.+ handlers = opener.handlers+ refusers = [+ h for h in handlers+ if isinstance(h, preflight_module._PreflightNoRedirectHandler)+ ]+ assert len(refusers) == 1, (+ f"expected exactly one no-redirect handler in the opener, got {len(refusers)}"+ )+++def test_no_redirect_handler_returns_none_on_30x(preflight_module):+ """Every 30x method on the handler returns None (= refuse)."""+ handler = preflight_module._PreflightNoRedirectHandler()+ for code, method in (+ (301, "http_error_301"),+ (302, "http_error_302"),+ (303, "http_error_303"),+ (307, "http_error_307"),+ (308, "http_error_308"),+ ):+ result = getattr(handler, method)(None, None, code, "msg", {})+ assert result is None, f"expected None from {method}, got {result!r}"