The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(skills-hub): sitemap fetches reuse the hub's guarded GET
teknium15236a58005bc
diff --git a/tools/skills_hub_skillssh.py b/tools/skills_hub_skillssh.pyindex 634b0965ed1..cc357449cfe 100644--- a/tools/skills_hub_skillssh.py+++ b/tools/skills_hub_skillssh.py@@ -7,7 +7,7 @@ from typing import Any, Dict, List, Optionalfrom tools.skills_hub_github import GitHubAuth, GitHubSource, _split_repo_idfrom tools.skills_hub_models import (- SkillBundle, SkillMeta, SkillSource, _cache_metas, _cached_metas, _get_json, _get_text, _memo_json,+ SkillBundle, SkillMeta, SkillSource, _cache_metas, _cached_metas, _get_json, _get_text, _memo_json, hub,)logger = logging.getLogger("tools.skills_hub")@@ -29,7 +29,6 @@ class SkillsShSource(SkillSource):# skills.sh serves per-skill sitemaps brotli-compressed and httpx's optional# brotlicffi backend has a streaming-decode bug on them; asking for gzip# only makes the server fall back to gzip/identity on every httpx install.- _SITEMAP_HEADERS = {"Accept-Encoding": "gzip"}_SITEMAP_LOC_RE = re.compile(r"<loc>([^<]+)</loc>", re.IGNORECASE)_SITEMAP_SKILL_RE = re.compile(r"^https?://(?:www\.)?skills\.sh/(?P<owner>[^/]+)/(?P<repo>[^/]+)/(?P<skill>[^/]+)/?$", re.IGNORECASE,@@ -123,28 +122,24 @@ class SkillsShSource(SkillSource):if cached is not None:return cached[:limit] if limit > 0 else cached+ # Every hop goes through the hub's guarded GET: the index is a root of trust+ # that may redirect, and its <loc> entries are remote-party-controlled — a+ # hostile index could point a sitemap at an internal address.+ def _xml(url: str, timeout: int) -> Optional[str]:+ resp = hub()._guarded_http_get(url, timeout=timeout)+ return resp.text if resp is not None and resp.status_code == 200 else None+# Step 1: sitemap index -> per-skill sitemap URLs.- index_xml = _get_text(self.SITEMAP_INDEX_URL, follow_redirects=True, headers=self._SITEMAP_HEADERS)- # <loc> targets are remote-party-controlled — a hostile index could point a- # sitemap at an internal address; skip anything the SSRF guard rejects.- from tools.url_safety import is_safe_url+ index_xml = _xml(self.SITEMAP_INDEX_URL, 20)skill_sitemap_urls = [m.group(1).strip() for m in self._SITEMAP_LOC_RE.finditer(index_xml or "")- if "sitemap-skills" in m.group(1) and is_safe_url(m.group(1).strip())]+ if "sitemap-skills" in m.group(1)]if not skill_sitemap_urls:return self._featured_skills(limit)# Step 2: collect canonical "owner/repo/skill" IDs from each sitemap.- # The guarded client re-validates every redirect hop at connect time, so a- # safe-looking <loc> can't 302 to an internal target.- from tools.url_safety import create_ssrf_safe_clientseen, results = set(), []for sitemap_url in skill_sitemap_urls:- with create_ssrf_safe_client(timeout=30, follow_redirects=True) as client:- try:- resp = client.get(sitemap_url, headers=self._SITEMAP_HEADERS)- except Exception:- continue- xml = resp.text if resp.status_code == 200 else None+ xml = _xml(sitemap_url, 30)for loc_match in self._SITEMAP_LOC_RE.finditer(xml or ""):m = self._SITEMAP_SKILL_RE.match(loc_match.group(1).strip())if not m:diff --git a/website/docs/user-guide/security.md b/website/docs/user-guide/security.mdindex eb000d7e9ac..131a4ea993b 100644--- a/website/docs/user-guide/security.md+++ b/website/docs/user-guide/security.md@@ -739,6 +739,8 @@ All URL-capable tools (web search, web extract, vision, browser) validate URLs bSSRF protection is always active for internet-facing use and DNS failures are treated as blocked (fail-closed). Redirect chains are re-validated at each hop to prevent redirect-based bypasses.+The same guard covers fetches whose URL comes from a remote party rather than from you: image/video URLs returned by a generation provider, reference-image URLs a model supplies for edits, pet spritesheets and the petdex manifest, and skills.sh sitemap entries. A provider or index that points one of those at a private or metadata address is refused before any connection opens; the operator's own provider `base_url` is not affected, and an image-generation provider hosted on your LAN needs `security.allow_private_urls: true` (below) for its result URLs to be cached locally.+#### Intentionally allowing private URLsSome setups legitimately need private/internal URL access — home networks that resolve `home.arpa` to RFC 1918 space, LAN-only Ollama/llama.cpp endpoints, internal wikis, cloud metadata debugging, and the like. For those cases there's a global opt-out: