Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ def validate_proxy_server_image(proxy_server_image: str) -> None:
f"Proxy server image '{proxy_server_image}' must contain a tag with ':'"
" or a digest with '@'."
)
if not re.fullmatch(r"[A-Za-z0-9][A-Za-z0-9._/:@-]*", proxy_server_image):
raise ValueError(
f"Proxy server image '{proxy_server_image}' contains characters that"
" are not valid in a Docker image reference."
)


def validate_xla_flags(xla_flags: Iterable[str] | None) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,30 @@ def test_validate_proxy_server_image_success(self, image):
" with ':' or a digest with '@'."
),
),
dict(
testcase_name="newline_yaml_injection",
image="alpine/alpine:latest\n command: [sh, -c, 'id']",
expected_regex=(
"contains characters that are not valid in a Docker image"
" reference."
),
),
dict(
testcase_name="spaces_in_image",
image="gcr.io/project/image:tag extra_args",
expected_regex=(
"contains characters that are not valid in a Docker image"
" reference."
),
),
dict(
testcase_name="invalid_punctuation",
image="gcr.io/project/image:tag;echo pwn",
expected_regex=(
"contains characters that are not valid in a Docker image"
" reference."
),
),
)
def test_validate_proxy_server_image_failure(self, image, expected_regex):
"""Tests that invalid proxy server image strings raise a ValueError."""
Expand Down
Loading