TransportHttp: Include HTTP response body in 403 Forbidden error messages
@dahyvuun arbeitet bereits daran.
Seit 04.5.2026.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 56/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Ruhig
- Tech-Stack
- git, java
- Bereich
- backend, networking
Rechercherichtung
Start with the two HTTP_FORBIDDEN handlers in org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java, then inspect HttpConnection.java and JDKHttpConnection.java for the response-stream API. Check the existing transport tests and add coverage for a 403 response with a body and with no body. Done means both handlers preserve the current message and include the response body when available.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Description
Summary
When JGit receives an HTTP 403 (Forbidden) response during git-upload-pack or git-receive-pack, it constructs a generic error message:
git-upload-pack not permitted on https://github.example.com/org/repo.git
The actual reason for the rejection — which the server provides in the HTTP response body — is discarded. In contrast, the native git client reads and displays the response body, providing a much more informative error:
the repository owner has an IP allow list enabled, and <IP> is not permitted to access this repository.
This makes it significantly harder to diagnose access issues when using JGit-based tooling.
Steps to Reproduce
- Configure a GitHub repository (or GitHub Enterprise) with an IP allow list that blocks the client's IP address.
- Attempt to clone or fetch using JGit over HTTPS.
- Observe the error message.
JGit result:
org.eclipse.jgit.errors.TransportException: https://github.example.com/org/repo.git: git-upload-pack not permitted on https://github.example.com/org/repo.git/
Native git result:
fatal: unable to access 'https://github.example.com/org/repo.git/': The requested URL returned error: 403
the repository owner has an IP allow list enabled, and <IP> is not permitted to access this repository.
Expected Behavior
JGit should read the HTTP error response body on 403 responses and include it in the TransportException message, e.g.:
git-upload-pack not permitted on https://github.example.com/org/repo.git/: the repository owner has an IP allow list enabled, and <IP> is not permitted to access this repository.
Root Cause Analysis
In TransportHttp.java, both HTTP_FORBIDDEN handlers (in connect() at ~line 701 and in Service.sendRequest() at ~line 1710) construct the error message using only the URL and service name:
case HttpConnection.HTTP_FORBIDDEN:
throw new TransportException(uri, MessageFormat.format(
JGitText.get().serviceNotPermitted, baseUrl, service));
The HTTP response body (error stream) is never read. The HttpConnection interface also does not expose a getErrorStream() method, so even if the transport wanted to read it, there is no API to do so.
Proposed Fix
Three changes are needed:
1. Add getErrorStream() to HttpConnection interface
File: org.eclipse.jgit/src/org/eclipse/jgit/transport/http/HttpConnection.java
Add a default method (to maintain backward compatibility with custom implementations):
/**
* Returns an error stream for reading the HTTP error response body
* on error status codes (4xx, 5xx).
*
* @return the error stream, or {@code null} if not available
* @see java.net.HttpURLConnection#getErrorStream()
* @since 7.1
*/
default InputStream getErrorStream() {
return null;
}
2. Implement getErrorStream() in JDKHttpConnection
File: org.eclipse.jgit/src/org/eclipse/jgit/transport/http/JDKHttpConnection.java
@Override
public InputStream getErrorStream() {
return wrappedUrlConnection.getErrorStream();
}
3. Read error body in TransportHttp on 403 responses
File: org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java
Add a helper method:
private static String readErrorBody(HttpConnection conn) {
try {
InputStream errorStream = conn.getErrorStream();
if (errorStream == null) {
return null;
}
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(errorStream, UTF_8))) {
StringBuilder body = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
if (body.length() > 0) {
body.append(' ');
}
body.append(line);
if (body.length() > 4096) {
break; // Limit how much we read
}
}
String result = body.toString().trim();
// If response is HTML, strip tags for readability
if (result.contains("<") && result.contains(">")) {
result = result.replaceAll("<[^>]+>", " ")
.replaceAll("\\s+", " ")
.trim();
}
return result.isEmpty() ? null : result;
}
} catch (IOException e) {
return null;
}
}
Then update both HTTP_FORBIDDEN cases to:
case HttpConnection.HTTP_FORBIDDEN:
String forbiddenMsg = MessageFormat.format(
JGitText.get().serviceNotPermitted, baseUrl, service);
String errorBody = readErrorBody(conn);
if (errorBody != null && !errorBody.isEmpty()) {
forbiddenMsg += ": " + errorBody;
}
throw new TransportException(uri, forbiddenMsg);
Motivation
This issue was seen when an enterprise organisation decides to add IP allow list for that specific organisation. And when a clone was done it was not clear what the exact issue was since we thought it was due to token not having enough permission.
Alternatives considered
No response
Additional context
No response
- Vorherrschende Sprache
- Java
- Sterne
- 427
- Forks
- 116
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus eclipse-jgit/jgit
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 83/100
eclipse-jgit/jgit#329 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
eclipse-jgit/jgit#327 ·
-
Repository.create(boolean bare) should provide a no-arg overload that uses isBare()Evtl. wieder frei @hardikyadav12 hat das vor 77 Tagen übernommen, und es ist kein Pull Request offen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
eclipse-jgit/jgit#297 · 1 Kommentar ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 83/100
eclipse-jgit/jgit#293 · 2 Kommentare ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
eclipse-jgit/jgit#288 ·
Alle Issues in eclipse-jgit/jgit
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 67/100
constellation-app/constellation#2613 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 69/100
Vakore/ZappierGames#334 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
IETF-Hackathon/pqc-certificates#369 ·
Maintainer antworten meist innerhalb von 1 Tag
-
? - Needs Triage bot_watch bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
NVIDIA/cudf-spark-jni#5594 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 92/100