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)

オープン
#322 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
git, java

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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):

URLURIish parseException message
https://[email protected]:9/o/r.gituser=ghp_TOKEN, pass=nullTransportException: https://[email protected]:9/o/r.git: connection failed
https://user:[email protected]:9/o/r.gituser=user, pass=ghp_PASS TransportException: https://[email protected]:9/o/r.git: connection failed (password stripped, as designed)
https://:[email protected]:9/o/r.gituser=null, pass=null, host=null, path=:[email protected]:9/o/r.gitNotSupportedException: URI not supported: https:///:[email protected]:9/o/r.git
foo://[email protected]/o/r.gituser=ghp_TOKENNotSupportedException: 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 as uri.setPass(null) + ": " + s. This removes only the password.
  • Transport.open(...) throws new NotSupportedException(MessageFormat.format(JGitText.get().URINotSupported, uri)). This formats uri.toString(), which is format(includePassword=false), so again only the password is omitted. That is two places in Transport.open.
  • URIish.toString() never prints a password, but always prints the user. For https://:tok@host/... the FULL_URI pattern does not match an empty user followed by a password. The string falls through to the path group, so setUser/setPass are never set and the secret stays in the path. setPass(null) then cannot help.
  • Other call sites that print a URIish or a raw remote string were not audited.

Suggestions

  1. Add one safe formatter on URIish, for example toSafeString() or toString(Redaction), and use it in TransportException(URIish, …), Transport.open's URINotSupported, and the other messages that print a URI. Keep toString() and toPrivateString() as they are for compatibility.
  2. 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.
  3. Optional: make the redaction opt-in or opt-out through a system property or config key, if maintainers worry about changing message text.
  4. 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

主要言語
Java
スター
427
フォーク
116
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

eclipse-jgit/jgit のほかの issue

eclipse-jgit/jgit の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。