Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-16090 Better error message when JWT auth SIGNATURE_INVALID during token parsing (#737)

Jan Høydahlcf27e77daf3b
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 09f56031abb..8f8f393851a 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -701,6 +701,8 @@ Bug Fixes
* SOLR-15983: Fix ClassCastException in UpdateLog$LogReplayer.doReplay. (Christine Poerschke, David Smiley)
+* SOLR-16090: Better error message when JWT auth SIGNATURE_INVALID during token parsing (janhoy)
+
================== 8.11.2 ==================
Bug Fixes
diff --git a/solr/modules/jwt-auth/src/java/org/apache/solr/security/jwt/JWTAuthPlugin.java b/solr/modules/jwt-auth/src/java/org/apache/solr/security/jwt/JWTAuthPlugin.java
index 83fcb484fbe..0b468063d77 100644
--- a/solr/modules/jwt-auth/src/java/org/apache/solr/security/jwt/JWTAuthPlugin.java
+++ b/solr/modules/jwt-auth/src/java/org/apache/solr/security/jwt/JWTAuthPlugin.java
@@ -405,24 +405,29 @@ public class JWTAuthPlugin extends AuthenticationPlugin
String exceptionMessage =
authResponse.getJwtException() != null ? authResponse.getJwtException().getMessage() : "";
if (AuthCode.SIGNATURE_INVALID.equals(authResponse.getAuthCode())) {
- String issuer = jwtConsumer.processToClaims(header).getIssuer();
- if (issuer != null) {
- Optional<JWTIssuerConfig> issuerConfig =
- issuerConfigs.stream().filter(ic -> issuer.equals(ic.getIss())).findFirst();
- if (issuerConfig.isPresent() && issuerConfig.get().usesHttpsJwk()) {
- log.info(
- "Signature validation failed for issuer {}. Refreshing JWKs from IdP before trying again: {}",
- issuer,
- exceptionMessage);
- for (HttpsJwks httpsJwks : issuerConfig.get().getHttpsJwks()) {
- httpsJwks.refresh();
+ String jwt = parseAuthorizationHeader(header);
+ try {
+ String issuer = jwtConsumer.processToClaims(jwt).getIssuer();
+ if (issuer != null) {
+ Optional<JWTIssuerConfig> issuerConfig =
+ issuerConfigs.stream().filter(ic -> issuer.equals(ic.getIss())).findFirst();
+ if (issuerConfig.isPresent() && issuerConfig.get().usesHttpsJwk()) {
+ log.info(
+ "Signature validation failed for issuer {}. Refreshing JWKs from IdP before trying again: {}",
+ issuer,
+ exceptionMessage);
+ for (HttpsJwks httpsJwks : issuerConfig.get().getHttpsJwks()) {
+ httpsJwks.refresh();
+ }
+ authResponse = authenticate(header); // Retry
+ exceptionMessage =
+ authResponse.getJwtException() != null
+ ? authResponse.getJwtException().getMessage()
+ : "";
}
- authResponse = authenticate(header); // Retry
- exceptionMessage =
- authResponse.getJwtException() != null
- ? authResponse.getJwtException().getMessage()
- : "";
}
+ } catch (InvalidJwtException ex) {
+ /* ignored */
}
}