Skip to content

Commit b33ce7f

Browse files
committed
Auto merge of #6681 - hmarr:master, r=alexcrichton
Don't retry invalid credentials from git credential helpers If a git credential helper returns invalid credentials, we currently get stuck in an infinite retry loop by calling the credentials callback over and over, each time returning the same invalid credentials. This change means we only invoke the credential helper once. ## How to reproduce 1. Create a git credential store with some invalid credentials: ``` echo "https://example-user:[email protected]" > ~/invalid-store ``` 2. Tell git to use that as your credential store by adding this to your `~/.gitconfig`: ``` [credential] helper = store --file=/home/<user>/invalid-store ``` 3. Add an invalid Git dependency to a `Cargo.toml`. For instance: ``` [dependencies.fake-repository] git = "https://github.com/fake-user/fake-repository" version = ">= 1.0.0" ``` 4. Try to update the dependencies (e.g. with `cargo update` or `cargo build`). Cargo hangs forever, retrying the invalid credentials.
2 parents e15f43f + 96ab67b commit b33ce7f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/cargo/sources/git/utils.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,12 @@ where
503503
// but we currently don't! Right now the only way we support fetching a
504504
// plaintext password is through the `credential.helper` support, so
505505
// fetch that here.
506-
if allowed.contains(git2::CredentialType::USER_PASS_PLAINTEXT) {
506+
//
507+
// If ssh-agent authentication fails, libgit2 will keep calling this
508+
// callback asking for other authentication methods to try. Check
509+
// cred_helper_bad to make sure we only try the git credentail helper
510+
// once, to avoid looping forever.
511+
if allowed.contains(git2::CredentialType::USER_PASS_PLAINTEXT) && cred_helper_bad.is_none() {
507512
let r = git2::Cred::credential_helper(cfg, url, username);
508513
cred_helper_bad = Some(r.is_err());
509514
return r;

0 commit comments

Comments
 (0)