Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerrick Stolee <derrickstolee@github.com>2022-06-06 17:36:16 +0300
committerJunio C Hamano <gitster@pobox.com>2022-06-06 19:32:32 +0300
commit6dcbdc0d6616d7fbd2445aa2237b22e3c172ea85 (patch)
treef3aedc2e792cd64a0dfa14e246cc42cbd3613916 /t/t5516-fetch-push.sh
parentd516b2db0af2221bd6b13e7347abdcb5830b2829 (diff)
remote: create fetch.credentialsInUrl config
Users sometimes provide a "username:password" combination in their plaintext URLs. Since Git stores these URLs in plaintext in the .git/config file, this is a very insecure way of storing these credentials. Credential managers are a more secure way of storing this information. System administrators might want to prevent this kind of use by users on their machines. Create a new "fetch.credentialsInUrl" config option and teach Git to warn or die when seeing a URL with this kind of information. The warning anonymizes the sensitive information of the URL to be clear about the issue. This change currently defaults the behavior to "allow" which does nothing with these URLs. We can consider changing this behavior to "warn" by default if we wish. At that time, we may want to add some advice about setting fetch.credentialsInUrl=ignore for users who still want to follow this pattern (and not receive the warning). An earlier version of this change injected the logic into url_normalize() in urlmatch.c. While most code paths that parse URLs eventually normalize the URL, that normalization does not happen early enough in the stack to avoid attempting connections to the URL first. By inserting a check into the remote validation, we identify the issue before making a connection. In the old code path, this was revealed by testing the new t5601-clone.sh test under --stress, resulting in an instance where the return code was 13 (SIGPIPE) instead of 128 from the die(). However, we can reuse the parsing information from url_normalize() in order to benefit from its well-worn parsing logic. We can use the struct url_info that is created in that method to replace the password with "<redacted>" in our error messages. This comes with a slight downside that the normalized URL might look slightly different from the input URL (for instance, the normalized version adds a closing slash). This should not hinder users figuring out what the problem is and being able to fix the issue. As an attempt to ensure the parsing logic did not catch any unintentional cases, I modified this change locally to to use the "die" option by default. Running the test suite succeeds except for the explicit username:password URLs used in t5550-http-fetch-dumb.sh and t5541-http-push-smart.sh. This means that all other tested URLs did not trigger this logic. The tests show that the proper error messages appear (or do not appear), but also count the number of error messages. When only warning, each process validates the remote URL and outputs a warning. This happens twice for clone, three times for fetch, and once for push. Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t5516-fetch-push.sh')
-rwxr-xr-xt/t5516-fetch-push.sh32
1 files changed, 32 insertions, 0 deletions
diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index 2f04cf9a1c..a67acc3263 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -12,6 +12,7 @@ This test checks the following functionality:
* --porcelain output format
* hiderefs
* reflogs
+* URL validation
'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
@@ -1809,4 +1810,35 @@ test_expect_success 'refuse fetch to current branch of bare repository worktree'
git -C bare.git fetch -u .. HEAD:wt
'
+test_expect_success 'fetch warns or fails when using username:password' '
+ message="URL '\''https://username:<redacted>@localhost/'\'' uses plaintext credentials" &&
+ test_must_fail git -c fetch.credentialsInUrl=allow fetch https://username:password@localhost 2>err &&
+ ! grep "$message" err &&
+
+ test_must_fail git -c fetch.credentialsInUrl=warn fetch https://username:password@localhost 2>err &&
+ grep "warning: $message" err >warnings &&
+ test_line_count = 3 warnings &&
+
+ test_must_fail git -c fetch.credentialsInUrl=die fetch https://username:password@localhost 2>err &&
+ grep "fatal: $message" err >warnings &&
+ test_line_count = 1 warnings &&
+
+ test_must_fail git -c fetch.credentialsInUrl=die fetch https://username:@localhost 2>err &&
+ grep "fatal: $message" err >warnings &&
+ test_line_count = 1 warnings
+'
+
+
+test_expect_success 'push warns or fails when using username:password' '
+ message="URL '\''https://username:<redacted>@localhost/'\'' uses plaintext credentials" &&
+ test_must_fail git -c fetch.credentialsInUrl=allow push https://username:password@localhost 2>err &&
+ ! grep "$message" err &&
+
+ test_must_fail git -c fetch.credentialsInUrl=warn push https://username:password@localhost 2>err &&
+ grep "warning: $message" err >warnings &&
+ test_must_fail git -c fetch.credentialsInUrl=die push https://username:password@localhost 2>err &&
+ grep "fatal: $message" err >warnings &&
+ test_line_count = 1 warnings
+'
+
test_done