Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/resourceloader/resourceloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,19 @@ func loadResourceFromURLOrEnv(resourcePath string) ([]byte, error) {
// loadFromURL loads the content of a URL and returns it as a byte slice.
func loadFromURL(url string) ([]byte, error) {
// As cosign does: https://github.com/sigstore/cosign/blob/beb9cf21bc6741bc6e6b9736bdf57abfb91599c0/pkg/blob/load.go#L47
// By default it will attempt a maximum 10 redirects
// #nosec G107
resp, err := http.Get(url)
if err != nil {
return nil, fmt.Errorf("requesting URL: %w", err)
}
defer resp.Body.Close()

// Check if the response is OK
if resp.StatusCode != http.StatusOK {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about redirections, should we follow them?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a comment about that. By default the http.Get performs a maximum of 10 redirections

return nil, fmt.Errorf("loading URL: %s", resp.Status)
}

raw, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("loading URL response: %w", err)
Expand Down
Loading