Files
kevinveenbirkenbachandClaude Opus 5.5 ba4c2661e6 fix(registry): keep the registry token on the registry host across redirects
urllib forwards every request header on a redirect, so a blob or manifest request that the registry redirected to its CDN carried the bearer token to that third-party host, and a redirect or a Link next page could steer the client off https or to any host. utils/docker/redirect.py adds an opener whose redirect handler refuses a target that is not https and drops Authorization when the host changes; registry.py opens every request through it, and tag paging resolves Link next against the current URL and stops when it leaves https or the registry host.

Tests: test_registry.py patches the opener and covers the cross-host token drop, the refused http redirect and the off-registry Link next (negative control with main's registry.py: 24 failed, among them the token reaching the CDN host). quality-high green on this tree (19/19), test-external against the live registries included.

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 15:46:44 +00:00

20 lines
659 B
Python

from __future__ import annotations
import urllib.error
import urllib.request
from urllib.parse import urlparse
class HttpsRedirectHandler(urllib.request.HTTPRedirectHandler):
def redirect_request(self, req, fp, code, msg, headers, newurl):
target = urlparse(newurl)
if target.scheme != "https":
raise urllib.error.HTTPError(req.full_url, code, msg, headers, fp)
new = super().redirect_request(req, fp, code, msg, headers, newurl)
if target.netloc != urlparse(req.full_url).netloc:
new.remove_header("Authorization")
return new
OPENER = urllib.request.build_opener(HttpsRedirectHandler)