mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-28 22:06:31 +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>
33 lines
866 B
Python
33 lines
866 B
Python
from __future__ import annotations
|
|
|
|
import unittest
|
|
|
|
from utils.docker.digest import valid_digest
|
|
|
|
SHA256 = "sha256:" + "d" * 64
|
|
SHA512 = "sha512:" + "f" * 128
|
|
|
|
|
|
class TestValidDigest(unittest.TestCase):
|
|
def test_well_formed_sha256_and_sha512_pass(self) -> None:
|
|
self.assertEqual(valid_digest(SHA256), SHA256)
|
|
self.assertEqual(valid_digest(SHA512), SHA512)
|
|
|
|
def test_anything_that_could_name_another_path_is_dropped(self) -> None:
|
|
for value in (
|
|
"sha256:/../../etc",
|
|
"sha256:" + "d" * 63 + "/",
|
|
"sha256:" + "D" * 64,
|
|
"sha256:" + "d" * 64 + "\n",
|
|
"md5:" + "d" * 32,
|
|
"",
|
|
None,
|
|
42,
|
|
):
|
|
with self.subTest(value=value):
|
|
self.assertIsNone(valid_digest(value))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|