Skip to content

Commit 754a258

Browse files
AXIS2-6055 Restrict preemptive Basic Auth to HTTPS connections
Preemptive authentication sends credentials on the first request without waiting for a 401 challenge. Over plain HTTP, base64-encoded credentials are trivially interceptable. Add HTTPS check: preemptive auth only sends the Authorization header when the connection scheme is HTTPS. On HTTP, logs a warning and skips preemptive auth — credentials will still be sent via the normal challenge/response flow if the server requests them. Found by local Gemini Pro security review.
1 parent 5a4971f commit 754a258

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

  • modules/transport/http/src/main/java/org/apache/axis2/transport/http/impl/httpclient5

modules/transport/http/src/main/java/org/apache/axis2/transport/http/impl/httpclient5/RequestImpl.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,17 @@ public void enableAuthentication(HTTPAuthenticator authenticator) {
339339
// AXIS2-6055: Preemptive authentication — send credentials on the first
340340
// request without waiting for a 401 challenge. This was supported in
341341
// Axis2 1.7 (HC 4) but the TODO was never implemented for HC 5.
342+
// Only applies to Basic auth over HTTPS to prevent credential exposure.
342343
if (authenticator.getPreemptiveAuthentication() && username != null && password != null) {
343-
String credentials = username + ":" + password;
344-
String encoded = java.util.Base64.getEncoder().encodeToString(credentials.getBytes(java.nio.charset.StandardCharsets.UTF_8));
345-
httpRequestMethod.setHeader("Authorization", "Basic " + encoded);
344+
String scheme = httpRequestMethod.getScheme();
345+
if (!"https".equalsIgnoreCase(scheme)) {
346+
log.warn("Preemptive authentication skipped: connection is not HTTPS. " +
347+
"Credentials will not be sent preemptively over an insecure connection.");
348+
} else {
349+
String credentials = username + ":" + password;
350+
String encoded = java.util.Base64.getEncoder().encodeToString(credentials.getBytes(java.nio.charset.StandardCharsets.UTF_8));
351+
httpRequestMethod.setHeader("Authorization", "Basic " + encoded);
352+
}
346353
}
347354

348355
/* Customizing the priority Order */

0 commit comments

Comments
 (0)