libgit2 / libgit2/libgit2sharp

Credentials being cached between requests to separate remotes with the same URL

Đang mở
#1,894 4 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
C#
Star
3.5k
Fork
925
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu trong LibGit2Sharp/Core/ManagedHttpSmartSubtransport.cs, đặc biệt là CredentialCache static được ManagedHttpSmartSubtransportStream sử dụng. Tái hiện hai lần clone với cùng một URL và các credential provider riêng biệt, sau đó xác minh rằng provider thứ hai được gọi và các thông tin xác thực không hợp lệ không xác thực thành công.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
csharp, git
Lĩnh vực
authentication, security
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
50/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.