libgit2 / libgit2/libgit2sharp
Credentials being cached between requests to separate remotes with the same URL
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 3.5k
- Forks
- 925
- PR merge metrics
- No merged PRs in 30d
Description
The current implementation of ManagedHttpSmartSubtransportStream uses a static CredentialCache. The credentials in this cache are only differentiated by URL and authentication scheme, if you have two separate repositories configured with the same URL, it's possible to authenticate to a repository without providing valid credentials.
Reproduction steps
using System;
using System.Net;
using LibGit2Sharp;
namespace Example
{
class Program
{
static void Main(string[] args)
{
var uri = "<repository URL>";
var repo1 = Repository.Clone(uri, "directory1", new CloneOptions
{
BranchName = "main",
CredentialsProvider = CredentialsHandlerThatReturnsValidCredentials
}); // This will succeed
var repo2 = Repository.Clone(uri, "directory2", new CloneOptions
{
BranchName = "main",
CredentialsProvider = CredentialHandlerThatReturnsInvalidCredentials
}); // Invalid credential provider is never called, cached credentials from the first request are used
}
public static Credentials CredentialsHandlerThatReturnsValidCredentials(string url, string usernameFromUrl,
SupportedCredentialTypes types)
{
return new UsernamePasswordCredentials
{
Username = "<valid username>",
Password = "<valid password>"
};
}
public static Credentials CredentialHandlerThatReturnsInvalidCredentials(string url, string usernameFromUrl,
SupportedCredentialTypes types)
{
return new UsernamePasswordCredentials
{
Username = "invalid username",
Password = "invalid password"
};
}
}
}
Expected behavior
Second clone should not authenticate, invalid credentials supplied.
Actual behavior
Authenticates with repository successfully, as there has already been a successful authentication to that repository URL.
Version of LibGit2Sharp (release number or SHA1)
0.27.0-preview-0102
Operating system(s) tested; .NET runtime tested
macOS, .NET 5
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in LibGit2Sharp/Core/ManagedHttpSmartSubtransport.cs, especially the static CredentialCache used by ManagedHttpSmartSubtransportStream. Reproduce the two clones with the same URL and separate credential providers, then verify that the second provider is called and invalid credentials do not authenticate successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, git
- Domain
- authentication, security
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100