Merge pull request #5967 from seipan/fix/url-encode

Fix infinite loop in HTTP client by validating URLs before requests
This commit is contained in:
Kubernetes Prow Robot
2025-08-24 12:13:06 -07:00
committed by GitHub
2 changed files with 17 additions and 1 deletions

View File

@@ -311,7 +311,11 @@ func (fl *FileLoader) httpClientGetContent(path string) ([]byte, error) {
} else { } else {
hc = &http.Client{} hc = &http.Client{}
} }
resp, err := hc.Get(path) parsedURL, err := url.ParseRequestURI(path)
if err != nil {
return nil, errors.Wrap(err)
}
resp, err := hc.Get(parsedURL.String())
if err != nil { if err != nil {
return nil, errors.Wrap(err) return nil, errors.Wrap(err)
} }

View File

@@ -676,3 +676,15 @@ func setupOnDisk(t *testing.T) (filesys.FileSystem, filesys.ConfirmedDir) {
}) })
return fSys, dir return fSys, dir
} }
// TestLoaderHTTPMalformedURL tests that malformed URLs are properly handled
// to prevent infinite loops in http.Client.Get
func TestLoaderHTTPMalformedURL(t *testing.T) {
require := require.New(t)
malformedURL := "https://example.com/example?ref=main - ../../example/example.yaml"
l1 := NewLoaderOrDie(
RestrictionRootOnly, MakeFakeFs([]testData{}), filesys.Separator)
_, err := l1.Load(malformedURL)
require.Error(err)
require.Equal("HTTP Error: status code 500 (Internal Server Error)", err.Error())
}