Repository.Clone() : Cross host redirect not allowed
See original GitHub issueWindows Server 2008 R2 SP2 ASP.NET C# libgit2sharp 0.21.0.176
From CLI this git operation succeeds without issue :
git clone https://www.github.com/{org-name}/{repo-name}.git
The expected local repo is created in folder \{org-name}\{repo-name}
But when ASP.NET C# app attempts programmatically equivalent operation LibGit2Sharp.Repository.Clone()
of same GitHub URI an exception is thrown : “Cross host redirect not allowed”
In the Visual Studio debugger I can see that the URI is being formed and passed to Repository.Clone()
as expected – so this isn’t an issue with a malformed URI.
C# code :
var cloneOptions = new CloneOptions {
BranchName = "master",
Checkout = true,
CredentialsProvider = (url, user, cred) =>
new UsernamePasswordCredentials { Username = {username}, Password = {password}}
};
string cloneResult;
try {
cloneResult = Repository.Clone(
"https://www.github.com/{my-org}/{my-repo}.git",
"c:\github\{my-org}\{my-repo}",
cloneOptions);
} catch (LibGit2SharpException e) {}
Repository.Clone()
throws a run-time exception :
Cross host redirect not allowed : at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) at LibGit2Sharp.Core.Proxy.git_clone(String url, String workdir, GitCloneOptions& opts) at LibGit2Sharp.Repository.Clone(String sourceUrl, String workdirPath, CloneOptions options)
Apparently here is where libgit2sharp
throws the exception on line 188 : https://github.com/libgit2/libgit2/blob/master/src/netops.c
Issue Analytics
- State:
- Created 8 years ago
- Comments:17 (9 by maintainers)
Top GitHub Comments
GitHub canonicalizes its URLs as
https://github.com/{user}/{repo}(.git)
. You however keep usinghttps://www.github.com/
as a URL, which is a hostname which GitHub itself never produces, and it will redirect away from thewww
regardless of whether you claim to be a Git or a browser.As such, it counts as a cross-host redirect, since
github.com
andwww.github.com
are not the same hostname. If you remove that extraneouswww.
prefix, it should work.@john-grandy-opentable I trust that things worked out in the end - I’m closing this, it’s quite stale now.