Exception messages echo the user part of a remote URL, so a token used as the user name leaks (and https://:token@host leaks entirely)
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 35/100
- Type d'issue
- Bug
- Clarté
- Plutôt claire
- Activité
- Active
- Stack technique
- git, java
- Domaine
- networking, security
Piste de recherche
Start with URIish (the FULL_URI pattern and toString()), then Transport.open's URINotSupported message and the TransportException(URIish, String) constructors. Reproduce the four URLs from the report and check getMessage() and the cause chain. Done means no token appears in those messages, with the empty-user https://:token@host form also parsed or rejected. Maintainers still need to decide on the redaction format, so confirm that direction before editing.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Version
JGit 7.8.0.202609011348-r but master sources confirm it
Operating System
Windows
Bug description
Found and confirmed using [AI].
TransportException(URIish, String) and the "URI not supported" message print the URL with only the password removed. Many hosts take a personal access token as the user name (https://<token>@github.com/o/r.git), so the token appears in exception messages. Applications that show these messages to users, send them to logs, or hand them to automation (for example AI agents) then expose the token. In addition, https://:<token>@host/... is not parsed as user info at all, so even the password-stripping does nothing for it.
Environment
JGit 7.8.0.202609011348-r, Temurin JDK 21, Windows. I also read the current master sources and saw the same code. I did not run master.
Reproduction
URIish ui = new URIish(url);
System.out.println(ui.getUser() + " | " + ui.getPass() + " | " + ui.getHost() + " | " + ui.getPath());
System.out.println(ui);
try (Git g = Git.init().setDirectory(dir).call()) {
g.getRepository().getConfig().setString("remote", "origin", "url", url);
g.getRepository().getConfig().save();
g.fetch().setRemote("origin")
.setRefSpecs("+refs/heads/*:refs/remotes/origin/*")
.setTimeout(5).call();
}Results (ghp_TOKEN, ghp_PASS, ghp_PWONLY stand for secrets):
| URL | URIish parse | Exception message |
|---|---|---|
| https://[email protected]:9/o/r.git | user=ghp_TOKEN, pass=null | TransportException: https://[email protected]:9/o/r.git: connection failed |
| https://user:[email protected]:9/o/r.git | user=user, pass=ghp_PASS | TransportException: https://[email protected]:9/o/r.git: connection failed (password stripped, as designed) |
| https://:[email protected]:9/o/r.git | user=null, pass=null, host=null, path=:[email protected]:9/o/r.git | NotSupportedException: URI not supported: https:///:[email protected]:9/o/r.git |
| foo://[email protected]/o/r.git | user=ghp_TOKEN | NotSupportedException: URI not supported: foo://[email protected]/o/r.git |
In the third and fourth rows the FetchCommand surfaces a JGitInternalException whose root cause carries that text.
Expected
No secret is printed. At minimum, the https://:token@host form should not leak, and a user part that is really a token should not be printed.
Analysis
TransportException(URIish uri, String s)and(URIish, String, Throwable)build the message asuri.setPass(null) + ": " + s. This removes only the password.Transport.open(...)throwsnew NotSupportedException(MessageFormat.format(JGitText.get().URINotSupported, uri)). This formatsuri.toString(), which isformat(includePassword=false), so again only the password is omitted. That is two places inTransport.open.URIish.toString()never prints a password, but always prints the user. Forhttps://:tok@host/...theFULL_URIpattern does not match an empty user followed by a password. The string falls through to the path group, sosetUser/setPassare never set and the secret stays in the path.setPass(null)then cannot help.- Other call sites that print a
URIishor a raw remote string were not audited.
Suggestions
- Add one safe formatter on
URIish, for exampletoSafeString()ortoString(Redaction), and use it inTransportException(URIish, …),Transport.open'sURINotSupported, and the other messages that print a URI. KeeptoString()andtoPrivateString()as they are for compatibility. - Fix the empty-user parse.
https://:token@host/...should parse as user="" and password=token, or be rejected without echoing the raw string.setPass(null)would then work for it. - Optional: make the redaction opt-in or opt-out through a system property or config key, if maintainers worry about changing message text.
- Add tests for the four URLs above. They should assert that the secret is absent from
getMessage()and from the full cause chain.
Precedent in git: git's transport_anonymize_url() (transport.c) strips the user name and password from every URL it prints, for all schemes, including https://:token@host/.... I ran git 2.56.1 against the four URLs above and none of the secrets appeared in its output. Suggestion: have URIish provide a message-safe form that follows the same rule (drop everything between scheme:// and the first @, unless the @ comes after the first /), and use it wherever a URI goes into an exception message. Whether the ssh://git@ user is kept is a judgment call for the maintainers; git does not keep it.
Actual behavior
tokens can end up logged via exception text
Expected behavior
credentials should not leak into logs
Relevant log output
Other information
No response
- Langage dominant
- Java
- Étoiles
- 427
- Forks
- 116
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de eclipse-jgit/jgit
-
Difficulté 2/5 1-3 heures Accessibilité débutants 83/100
eclipse-jgit/jgit#329 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 77/100
eclipse-jgit/jgit#327 ·
-
Repository.create(boolean bare) should provide a no-arg overload that uses isBare()Peut-être à nouveau libre @hardikyadav12 l’a pris il y a 77 jours, et aucune pull request n’est ouverte. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
eclipse-jgit/jgit#297 · 1 commentaire ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 83/100
eclipse-jgit/jgit#293 · 2 commentaires ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
eclipse-jgit/jgit#288 ·
Toutes les issues de eclipse-jgit/jgit
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 67/100
constellation-app/constellation#2613 ·
Les mainteneurs répondent en général sous 2 jours
-
[JUKEBOW] Arrows can be stolenOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 69/100
Vakore/ZappierGames#334 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
IETF-Hackathon/pqc-certificates#369 ·
Les mainteneurs répondent en général sous 1 jour
-
? - Needs Triage bot_watch bug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
NVIDIA/cudf-spark-jni#5594 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 92/100