Skip to content

Commit 734a4a3

Browse files
committed
fix(image-service): add separate url parsing check for http-based images
1 parent 4fa9cff commit 734a4a3

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

cmd/metal-api/internal/service/image-service.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"log/slog"
77
"net/http"
8+
"net/url"
89
"strconv"
910
"strings"
1011
"time"
@@ -355,6 +356,11 @@ func checkImageURL(id, inputURL string, ociCredentials authn.Authenticator) erro
355356

356357
switch parsedURL[0] {
357358
case "http", "https":
359+
_, err := url.ParseRequestURI(inputURL)
360+
if err != nil {
361+
return fmt.Errorf("image:%s could not be parsed. error:%w", inputURL, err)
362+
}
363+
358364
res, err := http.Head(inputURL)
359365
if err != nil {
360366
return fmt.Errorf("image:%s is not accessible under:%s error:%w", id, inputURL, err)

cmd/metal-api/internal/service/image-service_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ func TestDeleteImage(t *testing.T) {
110110

111111
func TestCheckImageURL(t *testing.T) {
112112
t.Run("Invalid URL", func(t *testing.T) {
113-
err := checkImageURL("testID", "http://invalid-ürl", nil)
114-
require.EqualError(t, err, "image:testID is not accessible under:http://invalid-ürl error:Head \"http://invalid-%C3%BCrl\": dial tcp: lookup xn--invalid-rl-heb: no such host")
113+
err := checkImageURL("testID", "http://invalid url", nil)
114+
require.EqualError(t, err, "image:http://invalid url could not be parsed. error:parse \"http://invalid url\": invalid character \" \" in host name")
115115
})
116116

117117
t.Run("HTTP URL with successful HEAD request", func(t *testing.T) {

0 commit comments

Comments
 (0)