diff --git a/pkg/libmirror/images/digests.go b/pkg/libmirror/images/digests.go index 94129292..b6bbccb1 100644 --- a/pkg/libmirror/images/digests.go +++ b/pkg/libmirror/images/digests.go @@ -195,16 +195,22 @@ func FindVexImage( return "", fmt.Errorf("parse reference: %w", err) } - split := strings.SplitN(vexImageName, ":", 2) - imagePath := split[0] - tag := split[1] + // Use LastIndex to correctly handle URLs with port (e.g., localhost:443/repo:tag) + splitIndex := strings.LastIndex(vexImageName, ":") + if splitIndex == -1 { + return "", fmt.Errorf("invalid vex image name format: %s", vexImageName) + } + imagePath := vexImageName[:splitIndex] + tag := vexImageName[splitIndex+1:] + // Add missing path segments to client if VEX image is in a subpath imageSegmentsRaw := strings.TrimPrefix(imagePath, client.GetRegistry()) - imageSegments := strings.Split(imageSegmentsRaw, "/") - - for i, segment := range imageSegments { - client = client.WithSegment(segment) - logger.Debugf("Segment %d: %s", i, segment) + imageSegmentsRaw = strings.TrimPrefix(imageSegmentsRaw, "/") + if imageSegmentsRaw != "" { + for _, segment := range strings.Split(imageSegmentsRaw, "/") { + client = client.WithSegment(segment) + logger.Debugf("Segment: %s", segment) + } } err = client.CheckImageExists(context.TODO(), tag) @@ -212,6 +218,9 @@ func FindVexImage( // Image not found, which is expected for non-vulnerable images return "", nil } + if err != nil { + return "", fmt.Errorf("check VEX image exists: %w", err) + } return vexImageName, nil } diff --git a/pkg/libmirror/layouts/layouts.go b/pkg/libmirror/layouts/layouts.go index afd0d8ef..3280b0f5 100644 --- a/pkg/libmirror/layouts/layouts.go +++ b/pkg/libmirror/layouts/layouts.go @@ -493,16 +493,22 @@ func FindVexImage( return "", fmt.Errorf("parse reference: %w", err) } - split := strings.SplitN(vexImageName, ":", 2) - imagePath := split[0] - tag := split[1] + // Use LastIndex to correctly handle URLs with port (e.g., localhost:443/repo:tag) + splitIndex := strings.LastIndex(vexImageName, ":") + if splitIndex == -1 { + return "", fmt.Errorf("invalid vex image name format: %s", vexImageName) + } + imagePath := vexImageName[:splitIndex] + tag := vexImageName[splitIndex+1:] + // Add missing path segments to client if VEX image is in a subpath imageSegmentsRaw := strings.TrimPrefix(imagePath, client.GetRegistry()) - imageSegments := strings.Split(imageSegmentsRaw, "/") - - for i, segment := range imageSegments { - client = client.WithSegment(segment) - logger.Debugf("Segment %d: %s", i, segment) + imageSegmentsRaw = strings.TrimPrefix(imageSegmentsRaw, "/") + if imageSegmentsRaw != "" { + for _, segment := range strings.Split(imageSegmentsRaw, "/") { + client = client.WithSegment(segment) + logger.Debugf("Segment: %s", segment) + } } err = client.CheckImageExists(context.TODO(), tag) @@ -510,6 +516,9 @@ func FindVexImage( // Image not found, which is expected for non-vulnerable images return "", nil } + if err != nil { + return "", fmt.Errorf("check VEX image exists: %w", err) + } return vexImageName, nil }