fix(registry): open only https bearer realms

A registry answering 401 names its token endpoint in the
WWW-Authenticate realm, and both v2 tag clients opened that realm with
any scheme. A file realm made test-external read that local JSON file,
an http realm reached any internal host, and the token value went back
to the registry as a Bearer header. utils/docker/registry.py
_bearer_token and utils/update/source.py registry_v2_tags now refuse a
realm whose scheme is not https; one test each proves that neither a
file nor an http realm is opened, and both fail without the change.

Found by the MEDUSA skeptic round of the IAM main merge (B310
utils/docker/registry.py:78).

🎯 Fix: 95 %
💥 Break: 3 %
💸 Cost: 100 %
⏱️ Time: 100 %
🛡️ Security: 100 %
🏆 Score: 92
🚦 Gate: ✅ 90/5, cost and time <= 100, security 100 %

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
kevinveenbirkenbachandClaude Opus 5.5 committed 2026-11-12 09:12:00 +00:00
1 parent 7900af9d14
commit 9dd01355c7
4 files changed
+42 -3

No files matched your search

@@ -162,6 +162,23 @@ class TestFetchRegistryTags(unittest.TestCase):
with mock.patch.object(registry.urllib.request, "urlopen", side_effect=_fake):
self.assertEqual(registry.fetch_registry_tags("ghcr.io/foo/bar"), ["2.0.0"])
def test_a_realm_other_than_https_is_never_opened(self) -> None:
for realm in ("file:///tmp/token.json", "http://169.254.169.254/token"):
challenge = {"WWW-Authenticate": f'Bearer realm="{realm}",service="reg"'}
with (
self.subTest(realm=realm),
mock.patch.object(
registry.urllib.request,
"urlopen",
side_effect=_http_error(401, challenge),
) as opened,
):
self.assertEqual(registry.fetch_registry_tags("ghcr.io/foo/bar"), [])
self.assertEqual(
[call.args[0].full_url for call in opened.call_args_list],
["https://ghcr.io/v2/foo/bar/tags/list?n=1000"],
)
def test_pagination_follows_link(self) -> None:
page1 = _Resp(
headers={"Link": '</v2/library/foo/tags/list?n=100&last=b>; rel="next"'},