Skip to content

Commit b02119c

Browse files
authored
Fail gracefully on invalid token strings (#51014)
When we receive a request with an Authorization header that contains a Bearer token that is not generated by us or that is malformed in some way, attempting to decode it as one of our own might cause a number of exceptions that are not IOExceptions. This commit ensures that we catch and log these too and call onResponse with `null, so that we can return 401 instead of 500. Resolves: #50497
1 parent 15a9fcd commit b02119c

File tree

1 file changed

+1
-1
lines changed
  • x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc

1 file changed

+1
-1
lines changed

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/TokenService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ void decodeToken(String token, ActionListener<UserToken> listener) {
526526
listener.onResponse(null);
527527
}
528528
}
529-
} catch (IOException e) {
529+
} catch (Exception e) {
530530
// could happen with a token that is not ours
531531
if (logger.isDebugEnabled()) {
532532
logger.debug("built in token service unable to decode token", e);

0 commit comments

Comments
 (0)