Skip to content

ContainerRegistry: Reject invalid image tags and digests #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2025

Conversation

euanh
Copy link
Collaborator

@euanh euanh commented Jun 9, 2025

Motivation

ImageReference does not check for illegal characters in parsed image
digests and tags. This means that containertool will send illegal image
names to the registry. The registry will reject them, but the error
message might not explain why, so a generic error message will be
printed. Runtimes reject illegal image references immediately, without
sending them to the registry.

Some desktop runtimes accept local image names which the registry will
reject; other runtimes reject these names even for local names. containertool
now also rejects them.

Modifications

  • Check validity of tags and digests when parsing image names
  • Change the low-level API functions to accept Digest or Reference instead of String.

Result

It is impossible to create a Repository object containing a malformed
tag or digest, because the constructor checks the string value. It is impossible
to send a malformed name to the registry because the API wrappers only
accept Digest or Reference (Digest | Tag) objects.

Fixes #139

Test Plan

Existing tests continue to pass.
New tests exercise additional checks which were previously missing.
Removed tests which checked tags which seemed to be accepted by some desktop runtimes, but which were not accepted by registries.

@euanh euanh added kind/bug Something isn't working semver/patch No public API change. labels Jun 9, 2025
@euanh euanh force-pushed the 139-validate-tags branch 2 times, most recently from e864cf8 to 738e3ec Compare June 9, 2025 08:54
@euanh euanh force-pushed the 139-validate-tags branch from 738e3ec to 9e293d6 Compare June 9, 2025 09:01
@euanh euanh merged commit 931db31 into apple:main Jun 9, 2025
23 checks passed
@euanh euanh deleted the 139-validate-tags branch June 9, 2025 10:38
euanh added a commit to euanh/swift-container-plugin that referenced this pull request Jul 1, 2025
Motivation
----------

`ImageReference` does not check for illegal characters in parsed image
digests and tags. This means that `containertool` will send illegal
image
names to the registry. The registry will reject them, but the error
message might not explain why, so a generic error message will be
printed. Runtimes reject illegal image references immediately, without
sending them to the registry.

Some desktop runtimes accept local image names which the registry will 
reject; other runtimes reject these names even for local names.
`containertool`
now also rejects them.

Modifications
-------------

* Check validity of tags and digests when parsing image names
* Change the low-level API functions to accept `Digest` or `Reference`
instead of `String`.

Result
------

It is impossible to create a `Repository` object containing a malformed
tag or digest, because the constructor checks the string value. It is
impossible
to send a malformed name to the registry because the API wrappers only
accept `Digest` or `Reference (Digest | Tag)` objects.

Fixes apple#139 

Test Plan
---------

Existing tests continue to pass.
New tests exercise additional checks which were previously missing.
Removed tests which checked tags which seemed to be accepted by some
desktop runtimes, but which were not accepted by registries.
euanh added a commit to euanh/swift-container-plugin that referenced this pull request Jul 1, 2025
Motivation
----------

`ImageReference` does not check for illegal characters in parsed image
digests and tags. This means that `containertool` will send illegal
image
names to the registry. The registry will reject them, but the error
message might not explain why, so a generic error message will be
printed. Runtimes reject illegal image references immediately, without
sending them to the registry.

Some desktop runtimes accept local image names which the registry will 
reject; other runtimes reject these names even for local names.
`containertool`
now also rejects them.

Modifications
-------------

* Check validity of tags and digests when parsing image names
* Change the low-level API functions to accept `Digest` or `Reference`
instead of `String`.

Result
------

It is impossible to create a `Repository` object containing a malformed
tag or digest, because the constructor checks the string value. It is
impossible
to send a malformed name to the registry because the API wrappers only
accept `Digest` or `Reference (Digest | Tag)` objects.

Fixes apple#139 

Test Plan
---------

Existing tests continue to pass.
New tests exercise additional checks which were previously missing.
Removed tests which checked tags which seemed to be accepted by some
desktop runtimes, but which were not accepted by registries.
euanh added a commit that referenced this pull request Jul 1, 2025
Motivation
----------

Cherry pick of #140.

`ImageReference` does not check for illegal characters in parsed image
digests and tags. This means that `containertool` will send illegal
image
names to the registry. The registry will reject them, but the error
message might not explain why, so a generic error message will be
printed. Runtimes reject illegal image references immediately, without
sending them to the registry.

Some desktop runtimes accept local image names which the registry will
reject; other runtimes reject these names even for local names.
`containertool`
now also rejects them.

Modifications
-------------

* Check validity of tags and digests when parsing image names
* Change the low-level API functions to accept `Digest` or `Reference`
instead of `String`.

Result
------

It is impossible to create a `Repository` object containing a malformed
tag or digest, because the constructor checks the string value. It is
impossible
to send a malformed name to the registry because the API wrappers only
accept `Digest` or `Reference (Digest | Tag)` objects.

Fixes #139 

Test Plan
---------

Existing tests continue to pass.
New tests exercise additional checks which were previously missing.
Removed tests which checked tags which seemed to be accepted by some
desktop runtimes, but which were not accepted by registries.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ContainerRegistry should validate characters used in image tags and digests
1 participant