Skip to content

Commit f5f0e13

Browse files
authored
Handle unexpected/unchecked exceptions correctly (elastic#49080) (elastic#49137)
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 fc505aa commit f5f0e13

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
@@ -93,7 +93,6 @@
9393
import java.io.IOException;
9494
import java.io.UnsupportedEncodingException;
9595
import java.net.URI;
96-
import java.net.URISyntaxException;
9796
import java.net.URL;
9897
import java.net.URLEncoder;
9998
import java.nio.charset.Charset;
@@ -434,7 +433,7 @@ private void handleUserinfoResponse(HttpResponse httpResponse, JWTClaimsSet veri
434433
httpResponse.getStatusLine().getReasonPhrase()));
435434
}
436435
}
437-
} catch (IOException | com.nimbusds.oauth2.sdk.ParseException | ParseException e) {
436+
} catch (Exception e) {
438437
claimsListener.onFailure(new ElasticsearchSecurityException("Failed to get user information from the UserInfo endpoint.",
439438
e));
440439
}
@@ -544,7 +543,7 @@ private void handleTokenResponse(HttpResponse httpResponse, ActionListener<Tuple
544543
}
545544
tokensListener.onResponse(new Tuple<>(accessToken, idToken));
546545
}
547-
} catch (IOException | com.nimbusds.oauth2.sdk.ParseException e) {
546+
} catch (Exception e) {
548547
tokensListener.onFailure(
549548
new ElasticsearchSecurityException("Failed to exchange code for Id Token using the Token Endpoint. " +
550549
"Unable to parse Token Response", e));
@@ -748,7 +747,7 @@ public void onFileChanged(Path file) {
748747
/**
749748
* Remote JSON Web Key source specified by a JWKSet URL. The retrieved JWK set is cached to
750749
* avoid unnecessary http requests. A single attempt to update the cached set is made
751-
* (with {@ling ReloadableJWKSource#triggerReload}) when the {@link IDTokenValidator} fails
750+
* (with {@link ReloadableJWKSource#triggerReload}) when the {@link IDTokenValidator} fails
752751
* to validate an ID Token (because of an unknown key) as this might mean that the OpenID
753752
* Connect Provider has rotated the signing keys.
754753
*/
@@ -795,7 +794,7 @@ public void completed(HttpResponse result) {
795794
reloadFutureRef.set(null);
796795
LOGGER.trace("Successfully refreshed and cached remote JWKSet");
797796
future.onResponse(null);
798-
} catch (IOException | ParseException e) {
797+
} catch (Exception e) {
799798
failed(e);
800799
}
801800
}
@@ -815,7 +814,7 @@ public void cancelled() {
815814
});
816815
return null;
817816
});
818-
} catch (URISyntaxException e) {
817+
} catch (Exception e) {
819818
future.onFailure(e);
820819
reloadFutureRef.set(null);
821820
}

0 commit comments

Comments
 (0)