libgit2 / libgit2/libgit2sharp

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

Aperta
#1,894 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
C#
Stelle
3.5k
Fork
925
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia in LibGit2Sharp/Core/ManagedHttpSmartSubtransport.cs, in particolare nella CredentialCache statica utilizzata da ManagedHttpSmartSubtransportStream. Riproduci i due cloni con lo stesso URL e provider di credenziali separati, quindi verifica che venga chiamato il secondo provider e che credenziali non valide non consentano un’autenticazione corretta.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp, git
Ambito
authentication, security
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
50/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.