libgit2 / libgit2/libgit2sharp
Credentials being cached between requests to separate remotes with the same URL
还没有人认领这个 Issue。
- 主要语言
- C#
- 星标
- 3.5k
- 派生
- 925
- PR 合并指标
- 30 天内没有已合并 PR
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 LibGit2Sharp/Core/ManagedHttpSmartSubtransport.cs 开始,重点检查 ManagedHttpSmartSubtransportStream 使用的静态 CredentialCache。使用相同的 URL 和彼此独立的凭据提供程序复现这两次克隆,然后验证第二个提供程序会被调用,并且无效凭据无法成功完成身份验证。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- csharp, git
- 领域
- authentication, security
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 50/100