mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
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:
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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())
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user