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): URL allowlist, path containment, atomic writes, SHA-256 helper (VULN-A03, A08, A10)

Daniel47baba872527
diff --git a/scripts/sync_flow.py b/scripts/sync_flow.py
index 9691729..6cf1942 100644
--- a/scripts/sync_flow.py
+++ b/scripts/sync_flow.py
@@ -18,6 +18,13 @@ 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
+
+
+def _validate_github_url(url):
+ """Abort if url does not target the expected GitHub API host."""
+ parsed = urllib.parse.urlparse(url)
+ if parsed.netloc != _ALLOWED_HOST:
+ raise ValueError(f"Blocked request to unexpected host: {parsed.netloc!r}")
PROMPT_STAGES = ["find", "leverage", "optimize", "win", "local"]
STATIC_FILES = [
("docs/01-framework/flow-framework.md", "flow-framework.md"),
@@ -69,6 +76,7 @@ def content_url(path, ref):
def api_get(path, ref, headers):
url = content_url(path, ref)
+ _validate_github_url(url)
request = urllib.request.Request(url, headers=headers)
try:
with urllib.request.urlopen(request, timeout=15) as response:
@@ -174,8 +182,34 @@ def prompt_readme(rows):
return "\n".join(lines) + "\n"
+def _sha256(content):
+ return hashlib.sha256(content.encode("utf-8")).hexdigest()
+
+
+def _atomic_write(path, content):
+ """Write content atomically via a temp file in the same directory."""
+ dir_ = path.parent
+ fd, tmp = tempfile.mkstemp(dir=dir_, suffix=".tmp")
+ try:
+ with os.fdopen(fd, "w", encoding="utf-8") as fh:
+ fh.write(content)
+ shutil.move(tmp, path)
+ except Exception:
+ try:
+ os.unlink(tmp)
+ except OSError:
+ pass
+ raise
+
+
def record_write(root, path, content, dry_run, changes):
+ resolved = path.resolve()
+ root_resolved = root.resolve()
+ if not str(resolved).startswith(str(root_resolved) + os.sep):
+ raise ValueError(f"Path traversal blocked: {resolved} is outside {root_resolved}")
+
rel = path.relative_to(root).as_posix()
+ changes.setdefault("hashes", {})[rel] = _sha256(content)
if path.exists():
current = path.read_text(encoding="utf-8")
bucket = "unchanged" if current == content else "updated"
@@ -185,7 +219,7 @@ def record_write(root, path, content, dry_run, changes):
print(f"{bucket}: {rel}", file=sys.stderr)
if not dry_run and bucket != "unchanged":
path.parent.mkdir(parents=True, exist_ok=True)
- path.write_text(content, encoding="utf-8")
+ _atomic_write(path, content)
def sync(args):
@@ -193,7 +227,7 @@ def sync(args):
refs = root / "skills" / "seo-flow" / "references"
today = datetime.date.today().isoformat()
headers = _base_headers()
- changes = {"added": [], "updated": [], "unchanged": []}
+ changes = {"added": [], "updated": [], "unchanged": [], "hashes": {}}
prompt_rows = []
for source, target in STATIC_FILES:
diff --git a/tests/test_sync_flow.py b/tests/test_sync_flow.py
index f90536e..47edbfa 100644
--- a/tests/test_sync_flow.py
+++ b/tests/test_sync_flow.py
@@ -138,3 +138,33 @@ def test_authed_headers_degrades_when_gh_missing(monkeypatch):
monkeypatch.setattr(sf.subprocess, "run", _fake_run)
headers = sf._authed_headers()
assert "Authorization" not in headers
+
+
+# ── Task 3 tests ──────────────────────────────────────────────────────────────
+
+def test_validate_github_url_blocks_non_github_host():
+ """_validate_github_url must reject any host other than api.github.com (VULN-A10)."""
+ sf = _load_sync_flow_module()
+ import pytest
+ with pytest.raises(ValueError, match="Blocked"):
+ sf._validate_github_url("https://evil.example.com/repos/AgriciDaniel/flow/contents/file.md")
+
+
+def test_validate_github_url_allows_github_api():
+ """_validate_github_url must not raise for api.github.com URLs (VULN-A10)."""
+ sf = _load_sync_flow_module()
+ # Should not raise
+ sf._validate_github_url("https://api.github.com/repos/AgriciDaniel/flow/contents/README.md")
+
+
+def test_record_write_blocks_path_traversal(tmp_path):
+ """record_write must raise ValueError if path escapes the root directory (VULN-A03)."""
+ sf = _load_sync_flow_module()
+ root = tmp_path / "root"
+ root.mkdir()
+ # Path outside root
+ escape_path = tmp_path / "escaped_file.txt"
+ changes = {"added": [], "updated": [], "unchanged": [], "hashes": {}}
+ import pytest
+ with pytest.raises(ValueError, match="Path traversal blocked"):
+ sf.record_write(root, escape_path, "bad content", dry_run=False, changes=changes)