CVE-2024-35194: Insufficient Information (NVD-CWE-noinfo)
value: Minder is a software supply chain security platform. Prior to version 0.0.50, Minder engine is susceptible to a denial of service from memory exhaustion that can be triggered from maliciously created templates. Minder engine uses templating to generate strings for various use cases such as URLs, messages for pull requests, descriptions for advisories. In some cases can the user control both the template and the params for it, and in a subset of these cases, Minder reads the generated template entirely into memory. When Minders templating meets both of these conditions, an attacker is able to generate large enough templates that Minder will exhaust memory and crash. This vulnerability is fixed in 0.0.50.
CWE description: There is insufficient information about the issue to classify it; details are unkown or unspecified.
Published: 2024-05-20T21:15Z
Repository: https://github.com/stacklok/minder
Language: Go
Files changed: internal/verifier/sigstore/container/container.go
Commit date: 2024-05-20 19:52:50 +0300
Commit message: Merge pull request from GHSA-8fmj-33gw-g7pw

Similarly to other readers, this also limits the size. In this case, it
was set to 10MB, since attestations can get pretty big.

Signed-off-by: Juan Antonio Osorio <ozz@stacklok.com>
Diff: diff --git a/internal/verifier/sigstore/container/container.go b/internal/verifier/sigstore/container/container.go
index f4334deff..27ca2d203 100644
--- a/internal/verifier/sigstore/container/container.go
+++ b/internal/verifier/sigstore/container/container.go
@@ -22,10 +22,11 @@ import (
 	"encoding/hex"
 	"encoding/json"
 	"encoding/pem"
 	"errors"
 	"fmt"
+	"io"
 	"net/http"
 	"strings"
 
 	"github.com/google/go-containerregistry/pkg/authn"
 	"github.com/google/go-containerregistry/pkg/crane"
@@ -47,10 +48,14 @@ import (
 
 var (
 	// ErrProvenanceNotFoundOrIncomplete is returned when there's no provenance info (missing .sig or attestation) or
 	// has incomplete data
 	ErrProvenanceNotFoundOrIncomplete = errors.New("provenance not found or incomplete")
+
+	// MaxAttestationsBytesLimit is the maximum number of bytes we're willing to read from the attestation endpoint
+	// We'll limit this to 10mb for now
+	MaxAttestationsBytesLimit int64 = 10 * 1024 * 1024
 )
 
 const (
 	sigstoreBundleMediaType01 = "application/vnd.dev.sigstore.bundle+json;version=0.1"
 )
@@ -289,12 +294,13 @@ func getAttestationReply(
 		}
 		return nil, fmt.Errorf("error doing request: %w", err)
 	}
 	defer resp.Body.Close()
 
+	lr := io.LimitReader(resp.Body, MaxAttestationsBytesLimit)
 	var attestationReply AttestationReply
-	if err := json.NewDecoder(resp.Body).Decode(&attestationReply); err != nil {
+	if err := json.NewDecoder(lr).Decode(&attestationReply); err != nil {
 		return nil, fmt.Errorf("error decoding response: %w", err)
 	}
 
 	return &attestationReply, nil
 }
@@ -444,11 +450,12 @@ func getSimpleSigningLayersFromSignatureManifest(manifestRef string, auth authn.
 	if err != nil {
 		return nil, fmt.Errorf("error getting signature manifest: %w", err)
 	}
 
 	// Parse the manifest
-	manifest, err := v1.ParseManifest(bytes.NewReader(mf))
+	r := io.LimitReader(bytes.NewReader(mf), MaxAttestationsBytesLimit)
+	manifest, err := v1.ParseManifest(r)
 	if err != nil {
 		return nil, fmt.Errorf("error parsing signature manifest: %w", err)
 	}
 
 	// Loop through its layers and extract the simple signing layers

Vulnerable code: 	if err := json.NewDecoder(resp.Body).Decode(&attestationReply); err != nil {
	manifest, err := v1.ParseManifest(bytes.NewReader(mf))
Fixed code: 	"io"

	// MaxAttestationsBytesLimit is the maximum number of bytes we're willing to read from the attestation endpoint
	// We'll limit this to 10mb for now
	MaxAttestationsBytesLimit int64 = 10 * 1024 * 1024
	lr := io.LimitReader(resp.Body, MaxAttestationsBytesLimit)
	if err := json.NewDecoder(lr).Decode(&attestationReply); err != nil {
	r := io.LimitReader(bytes.NewReader(mf), MaxAttestationsBytesLimit)
	manifest, err := v1.ParseManifest(r)