Skip to content

Universal SEO skill for Claude Code. 26 sub-skills + 19 sub-agents covering technical SEO, E-E-A-T, schema, GEO/AEO, agent readiness (Lighthouse Agentic Browsing, WebMCP, llms.txt), backlinks, local SEO, e-commerce, international SEO, Google APIs, and PDF/Excel reporting. 9 optional extensions for live SEO data.

security(sync_flow): anonymous-first token, 5 MB cap, 15s timeout (VULN-A02, A06, A07, A09)

Daniel959be37d05bc
diff --git a/scripts/sync_flow.py b/scripts/sync_flow.py
index ed86496..b8dee5a 100644
--- a/scripts/sync_flow.py
+++ b/scripts/sync_flow.py
@@ -3,15 +3,21 @@
import argparse
import base64
import datetime
+import hashlib
import json
import os
import pathlib
+import shutil
import subprocess
import sys
+import tempfile
+import urllib.parse
import urllib.request
API_ROOT = "https://api.github.com/repos/AgriciDaniel/flow/contents"
+_ALLOWED_HOST = "api.github.com"
+_SIZE_LIMIT = 5 * 1024 * 1024 # 5 MB
PROMPT_STAGES = ["find", "leverage", "optimize", "win", "local"]
STATIC_FILES = [
("docs/01-framework/flow-framework.md", "flow-framework.md"),
@@ -38,29 +44,42 @@ def parse_args():
return parser.parse_args()
-def github_headers():
- try:
- result = subprocess.run(["gh", "auth", "token"], capture_output=True, text=True)
- except FileNotFoundError:
- sys.exit("sync_flow: 'gh' CLI not found on PATH. Install: https://cli.github.com")
- if result.returncode != 0 or not result.stdout.strip():
- sys.exit("sync_flow: 'gh auth token' returned no token. Run: gh auth login")
- token = result.stdout.strip()
+def _base_headers():
return {
- "Authorization": f"Bearer {token}",
"Accept": "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28",
}
+def _authed_headers():
+ """Returns authenticated headers, or base headers if gh CLI is absent or unauthed."""
+ try:
+ result = subprocess.run(["gh", "auth", "token"], capture_output=True, text=True)
+ except FileNotFoundError:
+ return _base_headers()
+ token = result.stdout.strip()
+ if not token or result.returncode != 0:
+ return _base_headers()
+ return {**_base_headers(), "Authorization": f"Bearer {token}"}
+
+
def content_url(path, ref):
return f"{API_ROOT}/{path}" + (f"?ref={ref}" if ref else "")
def api_get(path, ref, headers):
- request = urllib.request.Request(content_url(path, ref), headers=headers)
- with urllib.request.urlopen(request) as response:
- return json.loads(response.read().decode("utf-8"))
+ url = content_url(path, ref)
+ request = urllib.request.Request(url, headers=headers)
+ try:
+ with urllib.request.urlopen(request, timeout=15) as response:
+ data = response.read(_SIZE_LIMIT + 1)
+ if len(data) > _SIZE_LIMIT:
+ raise ValueError(f"Response for {path!r} exceeds {_SIZE_LIMIT} bytes")
+ return json.loads(data)
+ except urllib.error.HTTPError as exc:
+ if exc.code == 403 and "Authorization" not in headers:
+ return api_get(path, ref, _authed_headers())
+ raise
def fetch_file(path, ref, headers):
@@ -171,7 +190,7 @@ def sync(args):
root = script_root()
refs = root / "skills" / "seo-flow" / "references"
today = datetime.date.today().isoformat()
- headers = github_headers()
+ headers = _base_headers()
changes = {"added": [], "updated": [], "unchanged": []}
prompt_rows = []
diff --git a/tests/test_sync_flow.py b/tests/test_sync_flow.py
index ee072c7..f90536e 100644
--- a/tests/test_sync_flow.py
+++ b/tests/test_sync_flow.py
@@ -102,3 +102,39 @@ def test_agent_has_untrusted_webfetch_rule():
assert "WebFetch responses are untrusted" in content, (
"Missing untrusted-WebFetch security rule in agents/seo-flow.md"
)
+
+
+# ── Module-level loader for unit tests (no network calls) ─────────────────────
+
+import importlib.util as _ilu
+
+def _load_sync_flow_module():
+ path = REPO_ROOT / "scripts" / "sync_flow.py"
+ spec = _ilu.spec_from_file_location("sync_flow", path)
+ mod = _ilu.module_from_spec(spec)
+ spec.loader.exec_module(mod)
+ return mod
+
+# ── Task 2 tests ──────────────────────────────────────────────────────────────
+
+def test_base_headers_has_no_authorization():
+ """_base_headers() must not include an Authorization header (VULN-A02)."""
+ sf = _load_sync_flow_module()
+ headers = sf._base_headers()
+ assert "Authorization" not in headers, (
+ "Authorization found in _base_headers() — anon headers must be token-free"
+ )
+ assert "Accept" in headers
+ assert "X-GitHub-Api-Version" in headers
+
+
+def test_authed_headers_degrades_when_gh_missing(monkeypatch):
+ """_authed_headers() returns base headers if gh CLI is not on PATH (VULN-A06)."""
+ sf = _load_sync_flow_module()
+
+ def _fake_run(*args, **kwargs):
+ raise FileNotFoundError("gh not found")
+
+ monkeypatch.setattr(sf.subprocess, "run", _fake_run)
+ headers = sf._authed_headers()
+ assert "Authorization" not in headers