VYPR
Moderate severityNVD Advisory· Published Oct 16, 2020· Updated Aug 4, 2024

containerd can be coerced into leaking credentials during image pull

CVE-2020-15157

Description

In containerd (an industry-standard container runtime) before version 1.2.14 there is a credential leaking vulnerability. If a container image manifest in the OCI Image format or Docker Image V2 Schema 2 format includes a URL for the location of a specific image layer (otherwise known as a “foreign layer”), the default containerd resolver will follow that URL to attempt to download it. In v1.2.x but not 1.3.0 or later, the default containerd resolver will provide its authentication credentials if the server where the URL is located presents an HTTP 401 status code along with registry-specific HTTP headers. If an attacker publishes a public image with a manifest that directs one of the layers to be fetched from a web server they control and they trick a user or system into pulling the image, they can obtain the credentials used for pulling that image. In some cases, this may be the user's username and password for the registry. In other cases, this may be the credentials attached to the cloud virtual instance which can grant access to other cloud resources in the account. The default containerd resolver is used by the cri-containerd plugin (which can be used by Kubernetes), the ctr development tool, and other client programs that have explicitly linked against it. This vulnerability has been fixed in containerd 1.2.14. containerd 1.3 and later are not affected. If you are using containerd 1.3 or later, you are not affected. If you are using cri-containerd in the 1.2 series or prior, you should ensure you only pull images from trusted sources. Other container runtimes built on top of containerd but not using the default resolver (such as Docker) are not affected.

Affected packages

Versions sourced from the GitHub Security Advisory.

PackageAffected versionsPatched versions
github.com/containerd/containerdGo
< 1.2.141.2.14

Affected products

1

Patches

1
1ead8d9deb3b

treat manifest provided URLs differently

https://github.com/containerd/containerdSergey KanzhelevSep 24, 2020via ghsa
2 files changed · +154 8
  • remotes/docker/fetcher.go+17 8 modified
    @@ -56,6 +56,23 @@ func (r dockerFetcher) Fetch(ctx context.Context, desc ocispec.Descriptor) (io.R
     	}
     
     	return newHTTPReadSeeker(desc.Size, func(offset int64) (io.ReadCloser, error) {
    +		if len(desc.URLs) > 0 {
    +			db := *r.dockerBase
    +			db.auth = nil // do not authenticate
    +			nr := dockerFetcher{
    +				dockerBase: &db,
    +			}
    +			for _, u := range desc.URLs {
    +				log.G(ctx).WithField("url", u).Debug("trying alternative url")
    +				rc, err := nr.open(ctx, u, desc.MediaType, offset)
    +				if err != nil {
    +					log.G(ctx).WithField("error", err).Debug("error trying url")
    +					continue // try one of the other urls.
    +				}
    +
    +				return rc, nil
    +			}
    +		}
     		for _, u := range urls {
     			rc, err := r.open(ctx, u, desc.MediaType, offset)
     			if err != nil {
    @@ -142,14 +159,6 @@ func (r dockerFetcher) open(ctx context.Context, u, mediatype string, offset int
     func (r *dockerFetcher) getV2URLPaths(ctx context.Context, desc ocispec.Descriptor) ([]string, error) {
     	var urls []string
     
    -	if len(desc.URLs) > 0 {
    -		// handle fetch via external urls.
    -		for _, u := range desc.URLs {
    -			log.G(ctx).WithField("url", u).Debug("adding alternative url")
    -			urls = append(urls, u)
    -		}
    -	}
    -
     	switch desc.MediaType {
     	case images.MediaTypeDockerSchema2Manifest, images.MediaTypeDockerSchema2ManifestList,
     		images.MediaTypeDockerSchema1Manifest,
    
  • remotes/docker/fetcher_test.go+137 0 modified
    @@ -23,7 +23,12 @@ import (
     	"math/rand"
     	"net/http"
     	"net/http/httptest"
    +	"net/url"
     	"testing"
    +
    +	"github.com/containerd/containerd/images"
    +	digest "github.com/opencontainers/go-digest"
    +	ocispec "github.com/opencontainers/image-spec/specs-go/v1"
     )
     
     func TestFetcherOpen(t *testing.T) {
    @@ -92,3 +97,135 @@ func TestFetcherOpen(t *testing.T) {
     		t.Fatal("expected error opening with invalid server response")
     	}
     }
    +
    +func TestFetcherFetch(t *testing.T) {
    +	content := make([]byte, 128)
    +	rand.New(rand.NewSource(1)).Read(content)
    +	start := 0
    +
    +	s := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
    +		t.Helper()
    +
    +		if r.RequestURI == "/404" {
    +			// no authorization must be provided with the initial GET
    +			if r.Header["Authorization"] != nil {
    +				t.Errorf("no authorization can be used with manifest-specified URLs")
    +				return
    +			}
    +
    +			rw.WriteHeader(http.StatusNotFound)
    +			return
    +		}
    +
    +		if r.RequestURI == "/401" {
    +			if r.Header["Authorization"] == nil {
    +				rw.Header().Set("Docker-Distribution-Api-Version", "registry/2.0")
    +				rw.Header().Set("WWW-Authenticate", "Basic realm=\"https://url\"")
    +				rw.WriteHeader(http.StatusUnauthorized)
    +				return
    +			}
    +
    +			// no authorization must be provided for manifest-defined URLs
    +			t.Errorf("no authorization can be used with manifest-specified URLs")
    +			return
    +		}
    +
    +		if r.Header["Authorization"] == nil {
    +			rw.Header().Set("Docker-Distribution-Api-Version", "registry/2.0")
    +			rw.Header().Set("WWW-Authenticate", "Basic realm=\"https://url\"")
    +			rw.WriteHeader(http.StatusUnauthorized)
    +			return
    +		}
    +
    +		// authorizer must set Authorize header for the manifest URL
    +		if start > 0 {
    +			rw.Header().Set("content-range", fmt.Sprintf("bytes %d-127/128", start))
    +		}
    +		rw.Header().Set("content-length", fmt.Sprintf("%d", len(content[start:])))
    +		rw.Write(content[start:])
    +	}))
    +	defer s.Close()
    +
    +	baseURL, _ := url.Parse(s.URL)
    +	db := &dockerBase{
    +		client: s.Client(),
    +		base:   *baseURL,
    +	}
    +	db.auth = NewAuthorizer(db.client, func(a string) (string, string, error) {
    +		return "Authorize", "Basic blah", nil
    +	})
    +
    +	f := dockerFetcher{dockerBase: db}
    +
    +	ctx := context.Background()
    +
    +	desc := ocispec.Descriptor{
    +		MediaType:   images.MediaTypeDockerSchema2Manifest,
    +		Digest:      digest.FromBytes([]byte("digest")),
    +		Size:        10,
    +		URLs:        []string{fmt.Sprintf("%s/404", s.URL), fmt.Sprintf("%s/401", s.URL)},
    +		Annotations: map[string]string{},
    +	}
    +
    +	rc, err := f.Fetch(ctx, desc)
    +	if err != nil {
    +		t.Fatalf("failed to open: %+v", err)
    +	}
    +	b, err := ioutil.ReadAll(rc)
    +	if err != nil {
    +		t.Fatal(err)
    +	}
    +	expected := content[0:]
    +	if len(b) != len(expected) {
    +		t.Errorf("unexpected length %d, expected %d", len(b), len(expected))
    +		return
    +	}
    +	for i, c := range expected {
    +		if b[i] != c {
    +			t.Errorf("unexpected byte %x at %d, expected %x", b[i], i, c)
    +			return
    +		}
    +	}
    +}
    +
    +func TestFetcherGetV2URLPaths(t *testing.T) {
    +	content := make([]byte, 128)
    +	rand.New(rand.NewSource(1)).Read(content)
    +	start := 0
    +
    +	s := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
    +		if start > 0 {
    +			rw.Header().Set("content-range", fmt.Sprintf("bytes %d-127/128", start))
    +		}
    +		rw.Header().Set("content-length", fmt.Sprintf("%d", len(content[start:])))
    +		rw.Write(content[start:])
    +	}))
    +	defer s.Close()
    +
    +	f := dockerFetcher{&dockerBase{
    +		client: s.Client(),
    +	}}
    +	ctx := context.Background()
    +
    +	desc := ocispec.Descriptor{
    +		MediaType:   images.MediaTypeDockerSchema2Manifest,
    +		Digest:      "digest",
    +		Size:        10,
    +		URLs:        []string{"first", "second"},
    +		Annotations: map[string]string{},
    +	}
    +
    +	urls, err := f.getV2URLPaths(ctx, desc)
    +
    +	if err != nil {
    +		t.Errorf("unexpected error %v", err)
    +		return
    +	}
    +
    +	// blobs and manifest/digest
    +	// URLs from the descriptor should not be added to the list of alternative sources
    +	if len(urls) != 2 {
    +		t.Errorf("unexpected number of urls: %d, expected %d", len(urls), 2)
    +		return
    +	}
    +}
    

Vulnerability mechanics

Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

11

News mentions

0

No linked articles in our index yet.