From b9a7f307056c4425ad7575717f12725099e9f4f1 Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Sat, 5 Oct 2024 23:53:09 +0800 Subject: [PATCH] fix --- proxy/proxy.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/proxy/proxy.go b/proxy/proxy.go index 1d2b958..ab24b39 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -35,18 +35,27 @@ func NoRouteHandler(cfg *config.Config, blacklist *config.Blacklist) gin.Handler rawPath := strings.TrimPrefix(c.Request.URL.RequestURI(), "/") re := regexp.MustCompile(`^(http:|https:)?/?/?(.*)`) matches := re.FindStringSubmatch(rawPath) + logw("Matches: %v", matches[2]) + + if len(matches) < 3 { + logw("Invalid URL: %s", rawPath) + c.String(http.StatusForbidden, "Invalid URL.") + return + } rawPath = "https://" + matches[2] - // 提取用户名和仓库名,格式为 / - pathParts := strings.Split(matches[2], "/") - if len(pathParts) < 3 { + // 提取用户名和仓库名,格式为 handle///* + pathmatches := regexp.MustCompile(`^([^/]+)/([^/]+)/([^/]+)/.*`) + pathParts := pathmatches.FindStringSubmatch(matches[2]) + if len(pathParts) < 4 { logw("Invalid path: %s", rawPath) c.String(http.StatusForbidden, "Invalid path; expected username/repo.") return } - username := pathParts[1] - repo := pathParts[2] + + username := pathParts[2] + repo := pathParts[3] logw("Blacklist Check > Username: %s, Repo: %s", username, repo) if blacklist.Blist == nil {