From 79bb10658aaccfaa26be72fea49fbf7986ae98d6 Mon Sep 17 00:00:00 2001 From: Willie Date: Wed, 7 Oct 2026 02:40:48 +0800 Subject: [PATCH] fix(install): strip submodule URL userinfo before query and fragment A ? or # inside the userinfo used to cut away the @ before it was found, leaving the credential in place. --- internal/install/submodule.go | 17 +++++++++-------- internal/install/submodule_test.go | 2 ++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/internal/install/submodule.go b/internal/install/submodule.go index 9c6414948..355b2b7ed 100644 --- a/internal/install/submodule.go +++ b/internal/install/submodule.go @@ -32,16 +32,17 @@ func (l gitlink) String() string { // accepts any text there, so this fails closed on the raw string: everything // before the last "@" goes, keeping only a well-formed "scheme://" prefix. func displayURL(raw string) string { + // Userinfo first: a "?" or "#" inside it must not hide the "@". + if at := strings.LastIndex(raw, "@"); at >= 0 { + if scheme, _, ok := strings.Cut(raw[:at], "://"); ok { + raw = scheme + "://" + raw[at+1:] + } else { + raw = raw[at+1:] + } + } raw, _, _ = strings.Cut(raw, "#") raw, _, _ = strings.Cut(raw, "?") - at := strings.LastIndex(raw, "@") - if at < 0 { - return raw - } - if scheme, _, ok := strings.Cut(raw[:at], "://"); ok { - return scheme + "://" + raw[at+1:] - } - return raw[at+1:] + return raw } // repoGitlinks lists the submodules recorded in HEAD of repoPath. extraEnv diff --git a/internal/install/submodule_test.go b/internal/install/submodule_test.go index 328031bd2..73c6a7e40 100644 --- a/internal/install/submodule_test.go +++ b/internal/install/submodule_test.go @@ -155,6 +155,8 @@ func TestGitlinkString_HidesURLCredentials(t *testing.T) { "s3cret@example.com:org/up.git": "example.com:org/up.git", "https:/user:s3cret@example.com/org/up.git": "example.com/org/up.git", "//user:s3cret@example.com/org/up.git": "example.com/org/up.git", + "https://user:s3cret?x@example.com/org/up.git": "https://example.com/org/up.git", + "https://user:s3cret#x@example.com/org/up.git": "https://example.com/org/up.git", } { got := gitlink{Path: "vendor/up", Commit: "abc", URL: raw}.String() if strings.Contains(got, "s3cret") || !strings.Contains(got, want) {