Skip to content

Commit 2b9d4c7

Browse files
authored
Handle unexpected/unchecked exceptions correctly (#49080) (#49139)
Ensures that methods that are called from different threads ( i.e. from the callbacks of org.apache.http.concurrent.FutureCallback ) catch `Exception` instead of only the expected checked exceptions. This resolves a bug where OpenIdConnectAuthenticator#mergeObjects would throw an IllegalStateException that was never caught causing the thread to hang and the listener to never be called. This would in turn cause Kibana requests to authenticate with OpenID Connect to timeout and fail without even logging anything relevant. This also guards against unexpected Exceptions that might be thrown by invoked library methods while performing the necessary operations in these callbacks.
1 parent 43f91a3 commit 2b9d4c7

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

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

+5-6
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@
9292
import java.io.IOException;
9393
import java.io.UnsupportedEncodingException;
9494
import java.net.URI;
95-
import java.net.URISyntaxException;
9695
import java.net.URL;
9796
import java.net.URLEncoder;
9897
import java.nio.charset.Charset;
@@ -433,7 +432,7 @@ private void handleUserinfoResponse(HttpResponse httpResponse, JWTClaimsSet veri
433432
httpResponse.getStatusLine().getReasonPhrase()));
434433
}
435434
}
436-
} catch (IOException | com.nimbusds.oauth2.sdk.ParseException | ParseException e) {
435+
} catch (Exception e) {
437436
claimsListener.onFailure(new ElasticsearchSecurityException("Failed to get user information from the UserInfo endpoint.",
438437
e));
439438
}
@@ -541,7 +540,7 @@ private void handleTokenResponse(HttpResponse httpResponse, ActionListener<Tuple
541540
}
542541
tokensListener.onResponse(new Tuple<>(accessToken, idToken));
543542
}
544-
} catch (IOException | com.nimbusds.oauth2.sdk.ParseException e) {
543+
} catch (Exception e) {
545544
tokensListener.onFailure(
546545
new ElasticsearchSecurityException("Failed to exchange code for Id Token using the Token Endpoint. " +
547546
"Unable to parse Token Response", e));
@@ -738,7 +737,7 @@ public void onFileChanged(Path file) {
738737
/**
739738
* Remote JSON Web Key source specified by a JWKSet URL. The retrieved JWK set is cached to
740739
* avoid unnecessary http requests. A single attempt to update the cached set is made
741-
* (with {@ling ReloadableJWKSource#triggerReload}) when the {@link IDTokenValidator} fails
740+
* (with {@link ReloadableJWKSource#triggerReload}) when the {@link IDTokenValidator} fails
742741
* to validate an ID Token (because of an unknown key) as this might mean that the OpenID
743742
* Connect Provider has rotated the signing keys.
744743
*/
@@ -785,7 +784,7 @@ public void completed(HttpResponse result) {
785784
reloadFutureRef.set(null);
786785
LOGGER.trace("Successfully refreshed and cached remote JWKSet");
787786
future.onResponse(null);
788-
} catch (IOException | ParseException e) {
787+
} catch (Exception e) {
789788
failed(e);
790789
}
791790
}
@@ -805,7 +804,7 @@ public void cancelled() {
805804
});
806805
return null;
807806
});
808-
} catch (URISyntaxException e) {
807+
} catch (Exception e) {
809808
future.onFailure(e);
810809
reloadFutureRef.set(null);
811810
}

0 commit comments

Comments
 (0)