Skip to content

Commit 8504dea

Browse files
committed
gplazma: check BEARER TOKEN empty case
Motivation As reported by KIT, a LoginNamePrincipal has started to appear in their logs ( (ticket #10723)). This was due the Bearer (with an empty token). In this case, getHeader("Authorization") returns a trimmed string, so the authorizationScheme ends up being set to HttpServletRequest.BASIC_AUTH. Indecipherable login credential for CMS at GridKa) Modification It should be checked not only whether the Authorization header is non-null, but also whether it is empty (i.e., an empty BEARER_TOKEN is being used). And the empty token should be rejected Acked-by: Tigran Mkrtchyan Target: master, 11.0, 10.2, 10.1, 10.0, 9.2 Require-book: no Require-notes: yes Patch: https://rb.dcache.org/r/14462/
1 parent 96de401 commit 8504dea

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

modules/common/src/main/java/org/dcache/auth/BearerTokenCredential.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public static Optional<String> getBearerTokenFromSubject(Subject subject) {
2323
private final String _token;
2424

2525
public BearerTokenCredential(String token) {
26+
checkArgument(!token.isEmpty(), "Bearer Token must not be empty");
2627
checkArgument(CharMatcher.ascii().matchesAllOf(token), "Bearer Token not ASCII");
2728
_token = token;
2829
}

modules/dcache/src/main/java/org/dcache/http/AuthenticationHandler.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,16 +439,22 @@ private Optional<AuthInfo> parseAuthenticationHeader(HttpServletRequest request)
439439
LOG.debug("No credentials found in Authorization header");
440440
return Optional.empty();
441441
}
442+
String authScheme;
443+
String authData;
442444

443445
if (header.length() == 0) {
444446
LOG.debug("Credentials in Authorization header are not-null, but are empty");
445447
return Optional.empty();
446448
}
447-
448449
int space = header.indexOf(" ");
449-
String authScheme =
450-
space >= 0 ? header.substring(0, space).toUpperCase() : HttpServletRequest.BASIC_AUTH;
451-
String authData = space >= 0 ? header.substring(space + 1) : header;
450+
451+
if (space < 0) {
452+
authScheme = header.toUpperCase();
453+
authData = "";
454+
} else {
455+
authScheme = header.substring(0, space).toUpperCase();
456+
authData = header.substring(space + 1);
457+
}
452458
return Optional.of(new AuthInfo(authScheme, authData));
453459
}
454460

0 commit comments

Comments
 (0)