Skip to content

The agent that grows with you

fix(skills-hub): keep the gzip-only Accept-Encoding pin on sitemap fetches

teknium1309023a00c33
diff --git a/tests/tools/test_skills_hub.py b/tests/tools/test_skills_hub.py
index a7d0e14b42d..bcc2dfc2bde 100644
--- a/tests/tools/test_skills_hub.py
+++ b/tests/tools/test_skills_hub.py
@@ -199,6 +199,32 @@ class TestSkillsShSource:
auth = MagicMock(spec=GitHubAuth)
return SkillsShSource(auth=auth)
+ def test_sitemap_fetches_go_through_guarded_get_and_ask_for_gzip_only(self, monkeypatch):
+ """Sitemap hops use the hub's guarded GET *and* keep the explicit
+ ``Accept-Encoding: gzip`` pin: skills.sh serves sitemaps brotli-compressed and
+ httpx's optional brotlicffi backend has a streaming-decode bug on them, so the
+ default ``gzip, deflate, br`` negotiation must never reach the server."""
+ monkeypatch.setattr("tools.skills_hub.is_safe_url", lambda _url: True)
+ monkeypatch.setattr("tools.skills_hub.check_website_access", lambda _url: None)
+ monkeypatch.setattr("tools.skills_hub_skillssh._cached_metas", lambda _key: None)
+ monkeypatch.setattr("tools.skills_hub_skillssh._cache_metas", lambda _key, _metas: None)
+ calls = []
+
+ def fake_get(url, *, timeout, headers=None):
+ calls.append((url, headers))
+ body = ("<sitemapindex><sitemap><loc>https://www.skills.sh/sitemap-skills-0.xml</loc></sitemap></sitemapindex>"
+ if url.endswith("/sitemap.xml") else
+ "<urlset><url><loc>https://skills.sh/acme/repo/my-skill</loc></url></urlset>")
+ return MagicMock(status_code=200, headers={}, text=body)
+
+ monkeypatch.setattr("tools.skills_hub._ssrf_safe_http_get", fake_get)
+
+ results = self._source()._sitemap_catalog(limit=5)
+
+ assert [r.identifier for r in results] == ["skills-sh/acme/repo/my-skill"]
+ assert [u for u, _ in calls] == ["https://www.skills.sh/sitemap.xml", "https://www.skills.sh/sitemap-skills-0.xml"]
+ assert all(h == {"Accept-Encoding": "gzip"} for _, h in calls), calls
+
@patch("tools.skills_hub._write_index_cache")
@patch("tools.skills_hub._read_index_cache", return_value=None)
@patch("tools.skills_hub.httpx.get")
diff --git a/tests/tools/test_skills_hub_clawhub.py b/tests/tools/test_skills_hub_clawhub.py
index ab5de69cc64..82cc6a59910 100644
--- a/tests/tools/test_skills_hub_clawhub.py
+++ b/tests/tools/test_skills_hub_clawhub.py
@@ -196,7 +196,7 @@ class TestClawHubSource(unittest.TestCase):
self.assertIn("SKILL.md", bundle.files)
self.assertEqual(bundle.files["SKILL.md"], "# Skill")
self.assertEqual(bundle.files["README.md"], "hello")
- mock_safe_get.assert_called_once_with("https://files.example/skill-md", timeout=20)
+ mock_safe_get.assert_called_once_with("https://files.example/skill-md", timeout=20, headers=None)
@patch("tools.skills_hub.httpx.get")
def test_fetch_falls_back_to_versions_list(self, mock_get):
diff --git a/tools/skills_hub.py b/tools/skills_hub.py
index 6fafdddabdb..10e72a876e6 100644
--- a/tools/skills_hub.py
+++ b/tools/skills_hub.py
@@ -84,16 +84,20 @@ _REDIRECT_STATUS_CODES = {301, 302, 303, 307, 308}
_MAX_SKILL_FETCH_REDIRECTS = 5
-def _ssrf_safe_http_get(url: str, *, timeout: int = 20) -> httpx.Response:
+def _ssrf_safe_http_get(url: str, *, timeout: int = 20,
+ headers: Optional[Dict[str, str]] = None) -> httpx.Response:
"""Fetch one URL with connect-time SSRF validation and no automatic redirects."""
from tools.url_safety import create_ssrf_safe_client
with create_ssrf_safe_client(timeout=timeout, follow_redirects=False) as client:
- return client.get(url)
+ return client.get(url, headers=headers)
-def _guarded_http_get(url: str, *, timeout: int = 20) -> Optional[httpx.Response]:
- """Fetch a URL with SSRF and redirect-target validation (each hop re-checked)."""
+def _guarded_http_get(url: str, *, timeout: int = 20,
+ headers: Optional[Dict[str, str]] = None) -> Optional[httpx.Response]:
+ """Fetch a URL with SSRF and redirect-target validation (each hop re-checked).
+
+ *headers* are plain request headers (no credentials) and are sent on every hop."""
from tools.url_safety import SSRFConnectionBlocked
current_url = url
@@ -113,7 +117,7 @@ def _guarded_http_get(url: str, *, timeout: int = 20) -> Optional[httpx.Response
return None
try:
- resp = _ssrf_safe_http_get(current_url, timeout=timeout)
+ resp = _ssrf_safe_http_get(current_url, timeout=timeout, headers=headers)
except (SSRFConnectionBlocked, httpx.HTTPError) as exc:
logger.debug("Skills Hub fetch failed for %s: %s", current_url, exc)
return None
diff --git a/tools/skills_hub_skillssh.py b/tools/skills_hub_skillssh.py
index cc357449cfe..5d7a94a8484 100644
--- a/tools/skills_hub_skillssh.py
+++ b/tools/skills_hub_skillssh.py
@@ -29,6 +29,7 @@ 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,
@@ -126,7 +127,7 @@ class SkillsShSource(SkillSource):
# 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)
+ resp = hub()._guarded_http_get(url, timeout=timeout, headers=self._SITEMAP_HEADERS)
return resp.text if resp is not None and resp.status_code == 200 else None
# Step 1: sitemap index -> per-skill sitemap URLs.