Skip to content

Commit a404f17

Browse files
authored
Fix issue preventing some SBOMs being fetched from Docker Hub (#1119)
* Fix typo'd accept header * Ensure we only parse the first line of the attestation * Changelog
1 parent f86f75d commit a404f17

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@ All notable changes to `src-cli` are documented in this file.
1111

1212
## Unreleased
1313

14+
## 5.8.2
15+
1416
### Added
1517

1618
- Support HTTP(S), SOCKS5, and UNIX Domain Socket proxies via SRC_PROXY environment variable. [#1120](https://github.com/sourcegraph/src-cli/pull/1120)
1719

20+
### Fixed
21+
22+
- Fixed a compatibility issue that prevented `src sbom fetch` from fetching some SBOMs [#1119](https://github.com/sourcegraph/src-cli/pull/1119)
23+
1824
## 5.8.1
1925

2026
### Fixed

cmd/src/sbom_fetch.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"bufio"
5+
"bytes"
56
"encoding/base64"
67
"encoding/json"
78
"flag"
@@ -262,8 +263,14 @@ type attestation struct {
262263
}
263264

264265
func extractSBOM(attestationBytes []byte) (string, error) {
266+
// Ensure we only use the first line - occasionally Cosign includes multiple lines
267+
lines := bytes.Split(attestationBytes, []byte("\n"))
268+
if len(lines) == 0 {
269+
return "", fmt.Errorf("attestation is empty")
270+
}
271+
265272
var a attestation
266-
if err := json.Unmarshal(attestationBytes, &a); err != nil {
273+
if err := json.Unmarshal(lines[0], &a); err != nil {
267274
return "", fmt.Errorf("failed to unmarshal attestation: %w", err)
268275
}
269276

cmd/src/sbom_utils.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func getImageDigestDockerHub(image string, tag string) (string, error) {
4646
return "", err
4747
}
4848
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
49-
req.Header.Add("Accept", "Accept: application/vnd.docker.distribution.manifest.v2+json, application/vnd.oci.image.manifest.v1+json")
49+
req.Header.Add("Accept", "application/vnd.docker.distribution.manifest.v2+json, application/vnd.oci.image.manifest.v1+json")
5050

5151
// Make the HTTP request
5252
resp, err := http.DefaultClient.Do(req)

0 commit comments

Comments
 (0)