[PATCH v3 2/3] remote: do not show credentials when relative_url() fails
- From
- Aniket Gupta <aniketgupta3001@gmail.com>
- Date
- Nov 5, 2026, 15:28 UTC
- Message-ID
- <20261105152842.566318-3-aniketgupta3001@gmail.com>
- In-Reply-To
- <20261105152842.566318-1-aniketgupta3001@gmail.com>
When relative_url() cannot resolve a URL, it names the URL in its error message. If the URL contains a user name and password, both end up in the message, and from there in terminal output and logs.
Pass the URL through transport_anonymize_url() first. Also name the URL that was passed in rather than what is left of it after some components have already been stripped off, which is what a user would recognize.
Signed-off-by: Aniket Gupta <aniketgupta3001@gmail.com> --- remote.c | 5 ++++- t/t0060-path-utils.sh | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/remote.c b/remote.c index 899d805b76..36834b129c 100644 --- a/remote.c +++ b/remote.c @@ -3078,9 +3078,12 @@ char *relative_url_gently(const char *remote_url, const char *url, url += 3; chopped = chop_last_dir(&remoteurl, is_relative); if (chopped < 0) { + char *anon = transport_anonymize_url(remote_url); + strbuf_addf(err, _("cannot strip one component off url '%s'"), - remoteurl); + anon); + free(anon); free(remoteurl); strbuf_release(&sb); return NULL; diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index 56faf5fe73..cea0d13429 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -394,6 +394,15 @@ test_submodule_relative_url "../" "$(pwd)/addtest" "../repo" "$(pwd)/repo" test_submodule_relative_url "../" "foo/bar" "../submodule" "../foo/submodule" test_submodule_relative_url "../" "foo" "../submodule" "../submodule" +test_expect_success 'relative_url() does not show credentials when it fails' ' + cat >expect <<-\EOF && + fatal: cannot strip one component off url '\''https://host.example/a'\'' + EOF + test_must_fail test-tool submodule resolve-relative-url "" \ + "https://user:secret@host.example/a" ../../../../../../x 2>actual && + test_cmp expect actual +' + test_submodule_relative_url "(null)" "../foo/bar" "../sub/a/b/c" "../foo/sub/a/b/c" test_submodule_relative_url "(null)" "../foo/bar" "../sub/a/b/c/" "../foo/sub/a/b/c" test_submodule_relative_url "(null)" "../foo/bar/" "../sub/a/b/c" "../foo/sub/a/b/c"
-- 2.43.0