Merge pull request #44567 from thaJeztah/relax_checkSupportedMediaType

distribution: checkSupportedMediaType: allow additional media-types
This commit is contained in:
Brian Goff 2022-12-02 15:22:54 -08:00 committed by GitHub
commit 676250adf9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 6 deletions

View file

@ -604,14 +604,12 @@ func (p *puller) pullSchema1(ctx context.Context, ref reference.Reference, unver
}
func checkSupportedMediaType(mediaType string) error {
supportedMediaTypes := []string{
"application/vnd.oci.image.",
"application/vnd.docker.",
}
lowerMt := strings.ToLower(mediaType)
for _, mt := range supportedMediaTypes {
if strings.HasPrefix(lowerMt, mt) {
// The should either be an exact match, or have a valid prefix
// we append a "." when matching prefixes to exclude "false positives";
// for example, we don't want to match "application/vnd.oci.images_are_fun_yolo".
if lowerMt == mt || strings.HasPrefix(lowerMt, mt+".") {
return nil
}
}

View file

@ -20,6 +20,22 @@ import (
)
var (
// supportedMediaTypes represents acceptable media-type(-prefixes)
// we use this list to prevent obscure errors when trying to pull
// OCI artifacts.
supportedMediaTypes = []string{
// valid prefixes
"application/vnd.oci.image",
"application/vnd.docker",
// these types may occur on old images, and are copied from
// defaultImageTypes below.
"application/octet-stream",
"application/json",
"text/html",
"",
}
// defaultImageTypes represents the schema2 config types for images
defaultImageTypes = []string{
schema2.MediaTypeImageConfig,