Skip to content

Commit fe321d3

Browse files
authored
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>
1 parent 2d7e6b3 commit fe321d3

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

internal/verifier/sigstore/container/container.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"encoding/pem"
2525
"errors"
2626
"fmt"
27+
"io"
2728
"net/http"
2829
"strings"
2930

@@ -49,6 +50,10 @@ var (
4950
// ErrProvenanceNotFoundOrIncomplete is returned when there's no provenance info (missing .sig or attestation) or
5051
// has incomplete data
5152
ErrProvenanceNotFoundOrIncomplete = errors.New("provenance not found or incomplete")
53+
54+
// MaxAttestationsBytesLimit is the maximum number of bytes we're willing to read from the attestation endpoint
55+
// We'll limit this to 10mb for now
56+
MaxAttestationsBytesLimit int64 = 10 * 1024 * 1024
5257
)
5358

5459
const (
@@ -291,8 +296,9 @@ func getAttestationReply(
291296
}
292297
defer resp.Body.Close()
293298

299+
lr := io.LimitReader(resp.Body, MaxAttestationsBytesLimit)
294300
var attestationReply AttestationReply
295-
if err := json.NewDecoder(resp.Body).Decode(&attestationReply); err != nil {
301+
if err := json.NewDecoder(lr).Decode(&attestationReply); err != nil {
296302
return nil, fmt.Errorf("error decoding response: %w", err)
297303
}
298304

@@ -446,7 +452,8 @@ func getSimpleSigningLayersFromSignatureManifest(manifestRef string, auth authn.
446452
}
447453

448454
// Parse the manifest
449-
manifest, err := v1.ParseManifest(bytes.NewReader(mf))
455+
r := io.LimitReader(bytes.NewReader(mf), MaxAttestationsBytesLimit)
456+
manifest, err := v1.ParseManifest(r)
450457
if err != nil {
451458
return nil, fmt.Errorf("error parsing signature manifest: %w", err)
452459
}

0 commit comments

Comments
 (0)