Skip to content

Commit 42e2c18

Browse files
authored
Merge pull request #4375 from evolvedbinary/hotfix/http-bearer-auth
Do not override Bearer Authentication with Basic Authentication
2 parents 12ae764 + 420cf1f commit 42e2c18

File tree

4 files changed

+367
-6
lines changed

4 files changed

+367
-6
lines changed

exist-core/src/main/java/org/exist/http/servlets/AbstractExistHttpServlet.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@ protected Subject authenticate(HttpServletRequest request, HttpServletResponse r
246246
}
247247
}
248248

249-
// Secondly try basic authentication
249+
// Secondly try basic authentication if there is no Authorization header or the Authorization header does not indicate Basic auth
250250
final String auth = request.getHeader("Authorization");
251-
if (auth == null && getDefaultUser() != null) {
251+
if ((auth == null || !auth.toLowerCase().startsWith("basic ")) && getDefaultUser() != null) {
252252
return getDefaultUser();
253253
}
254254
return getAuthenticator().authenticate(request, response, true);

exist-core/src/main/java/org/exist/http/servlets/BasicAuthenticator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ public Subject authenticate(
6161
String password = null;
6262

6363
try {
64-
if (credentials != null && credentials.startsWith("Basic")) {
65-
final byte[] c = Base64.decodeBase64(credentials.substring("Basic ".length()));
64+
if (credentials != null && credentials.toLowerCase().startsWith("basic ")) {
65+
final byte[] c = Base64.decodeBase64(credentials.substring("basic ".length()));
6666
final String s = new String(c, UTF_8);
6767
// LOG.debug("BASIC auth credentials: "+s);
6868
final int p = s.indexOf(':');
6969
username = p < 0 ? s : s.substring(0, p);
7070
password = p < 0 ? null : s.substring(p + 1);
7171
}
7272
} catch(final IllegalArgumentException iae) {
73-
LOG.warn("Invalid BASIC authentication header received: {}", iae.getMessage(), iae);
73+
LOG.warn("Invalid Basic Authentication header received: {}", iae.getMessage(), iae);
7474
credentials = null;
7575
}
7676

exist-core/src/main/java/org/exist/http/urlrewrite/XQueryURLRewrite.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ protected void service(final HttpServletRequest request, final HttpServletRespon
179179
} else {
180180
// Secondly try basic authentication
181181
final String auth = request.getHeader("Authorization");
182-
if (auth != null) {
182+
if (auth != null && auth.toLowerCase().startsWith("basic ")) {
183183
requestUser = authenticator.authenticate(request, response, sendChallenge);
184184
if (requestUser != null) {
185185
user = requestUser;

0 commit comments

Comments
 (0)