Skip to content

Commit 02e0c8f

Browse files
Fix double sending of response in TransportOpenIdConnectPrepareAuthenticationAction (#89930) (#89954)
This fixes an obvious bug where the listener was resolved twice if any of the first two failure conditions in the changed method were met. Prior to #89873 this would lead to a memory leak.
1 parent 5ebaefa commit 02e0c8f

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

docs/changelog/89930.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 89930
2+
summary: Fix double sending of response in `TransportOpenIdConnectPrepareAuthenticationAction`
3+
area: Authentication
4+
type: bug
5+
issues: []

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/oidc/TransportOpenIdConnectPrepareAuthenticationAction.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.elasticsearch.action.support.HandledTransportAction;
1414
import org.elasticsearch.common.Strings;
1515
import org.elasticsearch.common.inject.Inject;
16-
import org.elasticsearch.common.io.stream.Writeable;
1716
import org.elasticsearch.tasks.Task;
1817
import org.elasticsearch.transport.TransportService;
1918
import org.elasticsearch.xpack.core.security.action.oidc.OpenIdConnectPrepareAuthenticationAction;
@@ -24,7 +23,6 @@
2423
import org.elasticsearch.xpack.security.authc.oidc.OpenIdConnectRealm;
2524

2625
import java.util.List;
27-
import java.util.stream.Collectors;
2826

2927
public class TransportOpenIdConnectPrepareAuthenticationAction extends HandledTransportAction<
3028
OpenIdConnectPrepareAuthenticationRequest,
@@ -42,7 +40,7 @@ public TransportOpenIdConnectPrepareAuthenticationAction(
4240
OpenIdConnectPrepareAuthenticationAction.NAME,
4341
transportService,
4442
actionFilters,
45-
(Writeable.Reader<OpenIdConnectPrepareAuthenticationRequest>) OpenIdConnectPrepareAuthenticationRequest::new
43+
OpenIdConnectPrepareAuthenticationRequest::new
4644
);
4745
this.realms = realms;
4846
}
@@ -58,15 +56,17 @@ protected void doExecute(
5856
List<OpenIdConnectRealm> matchingRealms = this.realms.stream()
5957
.filter(r -> r instanceof OpenIdConnectRealm && ((OpenIdConnectRealm) r).isIssuerValid(request.getIssuer()))
6058
.map(r -> (OpenIdConnectRealm) r)
61-
.collect(Collectors.toList());
59+
.toList();
6260
if (matchingRealms.isEmpty()) {
6361
listener.onFailure(
6462
new ElasticsearchSecurityException("Cannot find OpenID Connect realm with issuer [{}]", request.getIssuer())
6563
);
64+
return;
6665
} else if (matchingRealms.size() > 1) {
6766
listener.onFailure(
6867
new ElasticsearchSecurityException("Found multiple OpenID Connect realm with issuer [{}]", request.getIssuer())
6968
);
69+
return;
7070
} else {
7171
realm = matchingRealms.get(0);
7272
}

0 commit comments

Comments
 (0)