mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-27 21:38:01 +00:00
The digest check pushed utils/docker/registry.py past the 500-line limit of the Python file-size lint. valid_digest and its pattern move unchanged into utils/docker/digest.py, registry.py imports it for its two call sites, and TestValidDigest moves to test_digest.py with the same cases. Tests: test_digest.py 2 passed, test_registry.py 37 passed, file-size lint passed, ruff clean; quality-high green on this tree (test 4/4, lint 15/15). Security 65 % comes from two MEDUSA findings on unchanged lines of the existing registry HTTP client, committed on the operator word: registry.py:106 (a redirect forwards the bearer token to any host, B310) and registry.py:142 (Link next may switch host, WEB-SSRF); both are fixed in cluster/registry-redirect-token-leak on fix/utils/docker/registry-redirect-auth. Accepted as by design after a skeptic review: WEB-SSRF at registry.py:299, 465 and 488 (https-pinned URLs with quoted path segments) and B310 at registry.py:79 (https-only token realm). 🎯 Fix: 95 % 💥 Break: 1 % 💸 Cost: – ⏱️ Time: – 🛡️ Security: 65 % 🏆 Score: 61 🚦 Gate: ⚠️ security 65 % < 100: committed on the operator word Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
20 lines
498 B
Python
20 lines
498 B
Python
from __future__ import annotations
|
|
|
|
import re
|
|
|
|
_DIGEST_RE = re.compile(r"sha256:[0-9a-f]{64}|sha512:[0-9a-f]{128}")
|
|
|
|
|
|
def valid_digest(value: object) -> str | None:
|
|
"""
|
|
Args:
|
|
value: a ``digest`` field or ``Docker-Content-Digest`` header.
|
|
|
|
Returns:
|
|
``value`` when it is ``sha256:`` or ``sha512:`` with lowercase hex of
|
|
the matching length, else ``None``.
|
|
"""
|
|
if isinstance(value, str) and _DIGEST_RE.fullmatch(value):
|
|
return value
|
|
return None
|