netbeans icon indicating copy to clipboard operation
netbeans copied to clipboard

git username with backslash

Open MaciejNiemczyk opened this issue 2 years ago • 7 comments

Apache NetBeans version

Apache NetBeans 19 release candidate

What happened

When you have backslash in git user name you cannot use git client. The error is http://user\name@gitserver/gitpath/repo.git: cannot open git-upload-pack

I tried modifying git config by entering double backslash or %5C, but outcome is same.

How to reproduce

Use git account with backslash in username and run any git command

Did this work correctly in an earlier version?

No / Don't know

Operating System

Windows 10 version 10.0 running on amd64; UTF-8; pl_PL (nb)

JDK

17.0.8; Java HotSpot(TM) 64-Bit Server VM 17.0.8+9-LTS-211

Apache NetBeans packaging

Apache NetBeans provided installer

Anything else

No response

Are you willing to submit a pull request?

No

MaciejNiemczyk avatar Sep 05 '23 21:09 MaciejNiemczyk

Any chance to correct this? In Netbeans 21 message change to Invalid URL http://user\name@gitserver/gitpath/repo.git

MaciejNiemczyk avatar Mar 08 '24 13:03 MaciejNiemczyk

Please provide a way to reproduce (for example by providing a public gitlab instance).

matthiasblaesing avatar Mar 09 '24 19:03 matthiasblaesing

It's hard to reproduce because I cannot find a git platform which gives a possibility to create username with backslash. We are using our client local gitlab repository which using username as LDAP login so we have logins like ex...

The best thing which I can find is to try cloning repo with some fake address, for example https://gitlab.com/test/test.git if you use username extest it gives error "Incorrect credentials for repository at https://gitlab.com/test/test.git" but if you use username ex\test the message is "Cannot connect to repository at https://gitlab.com/test/test.git" and using RawCap I can confirm that request wasn't send. The third option is to use username ex%5Ctest which gives error "Incorrect credentials for repository at https://gitlab.com/test/test.git" so it seems good, but if you look at Authorization header it contains BASIC BASE64 of "ex%5Ctest:pass" instead BASE64 of "ex\test:pass".

MaciejNiemczyk avatar Mar 11 '24 14:03 MaciejNiemczyk

Thanks for the suggested testing option and further investigation. I had a quick look at the implementation of org.eclipse.jgit.transport.URIish. If I'm not mistaken it has a to optimistic interpretation of what is allowed in an URL (at least the variant defined in RFC2396, which java.net.URI is modelled after). I'll investigate further and see if I can find a fix, that will be accepted by jgit.

matthiasblaesing avatar Mar 11 '24 21:03 matthiasblaesing

First test result: If you don't use the http transport, but the SSH transport, it works without problems.

matthiasblaesing avatar Mar 13 '24 20:03 matthiasblaesing

Upstream issue - lets see if this gets accepted: https://review.gerrithub.io/c/eclipse-jgit/jgit/+/1183413

matthiasblaesing avatar Mar 14 '24 20:03 matthiasblaesing

Stacktrace:

java.lang.IllegalArgumentException: Illegal character found in user-info: '\'
	at java.base/java.net.URLStreamHandler.setURL(URLStreamHandler.java:527)
	at java.base/java.net.URLStreamHandler.parseURL(URLStreamHandler.java:326)
	at java.base/java.net.URL.<init>(URL.java:801)
Caused: java.net.MalformedURLException: Illegal character found in user-info: '\'
	at java.base/java.net.URL.<init>(URL.java:806)
	at java.base/java.net.URL.<init>(URL.java:654)
	at java.base/java.net.URL.<init>(URL.java:590)
	at org.eclipse.jgit.transport.TransportHttp.toURL(TransportHttp.java:304)
	at org.eclipse.jgit.transport.TransportHttp.setURI(TransportHttp.java:319)
Caused: org.eclipse.jgit.errors.NotSupportedException: Invalid URL https://dummy\[email protected]/hallo.git
	at org.eclipse.jgit.transport.TransportHttp.setURI(TransportHttp.java:322)
	at org.eclipse.jgit.transport.TransportHttp.<init>(TransportHttp.java:290)
	at org.eclipse.jgit.transport.TransportHttp$1.open(TransportHttp.java:199)
	at org.eclipse.jgit.transport.Transport.open(Transport.java:527)
	at org.eclipse.jgit.transport.Transport.open(Transport.java:497)
	at org.netbeans.libs.git.jgit.commands.TransportCommand.openTransport(TransportCommand.java:198)
	at org.netbeans.libs.git.jgit.commands.ListRemoteObjectsCommand.runTransportCommand(ListRemoteObjectsCommand.java:50)
Caused: org.netbeans.libs.git.GitException: Invalid URL https://dummy\[email protected]/hallo.git
	at org.netbeans.libs.git.jgit.commands.ListRemoteObjectsCommand.runTransportCommand(ListRemoteObjectsCommand.java:56)
	at org.netbeans.libs.git.jgit.commands.TransportCommand.run(TransportCommand.java:168)
	at org.netbeans.libs.git.jgit.commands.GitCommand$1.run(GitCommand.java:56)
	at org.netbeans.libs.git.jgit.commands.GitCommand$1.run(GitCommand.java:53)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:571)
	at org.netbeans.libs.git.jgit.commands.GitCommand.execute(GitCommand.java:53)
	at org.netbeans.libs.git.GitClient.listRemoteBranches(GitClient.java:909)
	at org.netbeans.modules.git.client.GitClient$36.call(GitClient.java:582)
	at org.netbeans.modules.git.client.GitClient$36.call(GitClient.java:578)
	at org.openide.util.NetworkSettings.suppressAuthenticationDialog(NetworkSettings.java:138)
	at org.netbeans.modules.git.client.GitClient$CommandInvoker$1$1.call(GitClient.java:931)
	at org.netbeans.modules.git.client.GitClient$CommandInvoker$1.call(GitClient.java:956)
	at org.netbeans.modules.git.client.GitClient$CommandInvoker.runMethodIntern(GitClient.java:968)
	at org.netbeans.modules.git.client.GitClient$CommandInvoker.runMethod(GitClient.java:897)
	at org.netbeans.modules.git.client.GitClient$CommandInvoker.runMethod(GitClient.java:875)
	at org.netbeans.modules.git.client.GitClient.listRemoteBranches(GitClient.java:578)
[catch] at org.netbeans.modules.git.ui.clone.RepositoryStep$RepositoryStepProgressSupport.perform(RepositoryStep.java:302)
	at org.netbeans.modules.git.client.GitProgressSupport.performIntern(GitProgressSupport.java:92)
	at org.netbeans.modules.git.client.GitProgressSupport.run(GitProgressSupport.java:85)
	at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1420)
	at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
	at org.openide.util.lookup.Lookups.executeWith(Lookups.java:287)
	at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2035)

matthiasblaesing avatar Apr 26 '24 20:04 matthiasblaesing