libgit2 / libgit2/libgit2sharp
Credentials being cached between requests to separate remotes with the same URL
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- C#
- Estrellas
- 3.5k
- Forks
- 925
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza en LibGit2Sharp/Core/ManagedHttpSmartSubtransport.cs, especialmente en la CredentialCache estática utilizada por ManagedHttpSmartSubtransportStream. Reproduce las dos clonaciones con la misma URL y proveedores de credenciales separados, y verifica que se llame al segundo proveedor y que las credenciales no válidas no autentiquen correctamente.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- csharp, git
- Área
- authentication, security
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 50/100