Skip to content

Commit 4d7e69c

Browse files
committed
oci: do not require top-level mediaType
The top-level mediaType member was added in response to CVE-2021-41190, but while it is suggested (SHOULD) it is not required (MUST) and some older tools do not fill this mediaType field (such as skopeo, at least for "index.json"). I plan to use these jq-based validation scripts for umoci, but incompatibility with skopeo is a little annoying (since that is what we use to pull images for our tests). We can work around it for "index.json", but it seems incorrect to claim that an image is invalid because of a missing suggested field. Instead, add an informational message but still permit such images. Signed-off-by: Aleksa Sarai <[email protected]>
1 parent fab86e6 commit 4d7e69c

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

oci.jq

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,28 @@ def validate_oci_subject_haver:
250250
else . end
251251
;
252252

253+
# Some objects have .mediaType fields which SHOULD NOT be unset but are still
254+
# valid if they are missing, so we should emit a warning if they are unset but
255+
# do not error out.
256+
# usage: same as validate_IN(.mediaType; options).
257+
# https://github.com/opencontainers/image-spec/security/advisories/GHSA-77vh-xpmg-72qh (CVE-2021-41190)
258+
# https://github.com/opencontainers/image-spec/blob/v1.1.1/manifest.md
259+
# https://github.com/opencontainers/image-spec/blob/v1.1.1/image-index.md
260+
def validate_optional_mediatype(options):
261+
if has("mediaType") then
262+
validate_IN(.mediaType; options)
263+
else [
264+
# Output a warning message.
265+
("warning: top-level mediaType field is missing from object (see CVE-2021-41190)\nexpected one of:\n\t\([ options | tojson ] | join("\n\t"))\n" | stderr | empty),
266+
.
267+
] | last end
268+
;
269+
253270
# https://github.com/opencontainers/image-spec/blob/v1.1.1/image-index.md
254271
def validate_oci_index($opt):
255272
validate_IN(type; "object")
256273
| validate_IN(.schemaVersion; 2)
257-
| validate_IN(.mediaType; media_types_index)
274+
| validate_optional_mediatype(media_types_index)
258275
| if has("artifactType") then
259276
validate(.artifactType; type == "string")
260277
| validate_IN(.artifactType; null) # TODO acceptable values? (this check intentionally contradicts the one above so artifactType generates an error)
@@ -296,7 +313,7 @@ def validate_oci_index: validate_oci_index({});
296313
def validate_oci_image($opt):
297314
validate_IN(type; "object")
298315
| validate_IN(.schemaVersion; 2)
299-
| validate_IN(.mediaType; media_types_image)
316+
| validate_optional_mediatype(media_types_image)
300317
| if has("artifactType") then
301318
validate(.artifactType; type == "string")
302319
| validate_IN(.artifactType;

0 commit comments

Comments
 (0)