Skip to content
Open
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
10 changes: 8 additions & 2 deletions src/handlers/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import (
"strings"
"time"

"hubproxy/config"
"hubproxy/utils"

"github.com/gin-gonic/gin"
"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
"hubproxy/config"
"hubproxy/utils"
)

// DockerProxy Docker代理配置
Expand All @@ -38,6 +39,10 @@ func (rd *RegistryDetector) detectRegistryDomain(path string) (string, string) {
}
}

if _, exist := cfg.Registries["docker.io"]; exist {
return "docker.io", path
}
Comment on lines +42 to +44
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fallback logic incorrectly routes unrecognized registries to docker.io.

The current implementation treats ANY path without a matching registry prefix as a docker.io image. This causes incorrect routing when paths contain unrecognized registry domains.

Problem: Given path quay.io/myorg/image where quay.io is not configured but docker.io is configured:

  • Lines 35-40: No prefix match
  • Lines 42-44: Returns ("docker.io", "quay.io/myorg/image")
  • Result: Attempts to fetch docker.io/quay.io/myorg/image

The fallback should only apply to paths without a registry-like prefix (e.g., library/nginx), not to paths with unknown registry domains (e.g., quay.io/image).

Apply this diff to fix the logic:

+	// Check if path starts with a registry-like domain
+	firstPart := path
+	if idx := strings.Index(path, "/"); idx != -1 {
+		firstPart = path[:idx]
+	}
+	// If first part contains "." or ":", it looks like a registry domain
+	if strings.Contains(firstPart, ".") || strings.Contains(firstPart, ":") {
+		return "", path
+	}
+
 	if _, exist := cfg.Registries["docker.io"]; exist {
 		return "docker.io", path
 	}
🤖 Prompt for AI Agents
In src/handlers/docker.go around lines 42 to 44, the fallback currently always
returns ("docker.io", path) when no configured registry prefix matches, which
incorrectly rewrites paths that already contain an unknown registry host; change
the fallback to only select docker.io when the path has no registry-like prefix.
Specifically, extract the first path segment (strings.SplitN(path, "/", 2)[0])
and if that segment contains a '.' or ':' or equals "localhost" treat it as an
explicit (unknown) registry and return ("" , path) or otherwise return
("docker.io", path); update imports to include strings if needed.


return "", path
}

Expand All @@ -61,6 +66,7 @@ var registryDetector = &RegistryDetector{}

// InitDockerProxy 初始化Docker代理
func InitDockerProxy() {

registry, err := name.NewRegistry("registry-1.docker.io")
if err != nil {
fmt.Printf("创建Docker registry失败: %v\n", err)
Expand Down