Skip to content

Commit

Permalink
Fix double sending of response in TransportOpenIdConnectPrepareAuthen…
Browse files Browse the repository at this point in the history
…ticationAction (#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.
  • Loading branch information
original-brownbear committed Sep 9, 2022
1 parent 5ebaefa commit 02e0c8f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions docs/changelog/89930.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 89930
summary: Fix double sending of response in `TransportOpenIdConnectPrepareAuthenticationAction`
area: Authentication
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.elasticsearch.action.support.HandledTransportAction;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.transport.TransportService;
import org.elasticsearch.xpack.core.security.action.oidc.OpenIdConnectPrepareAuthenticationAction;
Expand All @@ -24,7 +23,6 @@
import org.elasticsearch.xpack.security.authc.oidc.OpenIdConnectRealm;

import java.util.List;
import java.util.stream.Collectors;

public class TransportOpenIdConnectPrepareAuthenticationAction extends HandledTransportAction<
OpenIdConnectPrepareAuthenticationRequest,
Expand All @@ -42,7 +40,7 @@ public TransportOpenIdConnectPrepareAuthenticationAction(
OpenIdConnectPrepareAuthenticationAction.NAME,
transportService,
actionFilters,
(Writeable.Reader<OpenIdConnectPrepareAuthenticationRequest>) OpenIdConnectPrepareAuthenticationRequest::new
OpenIdConnectPrepareAuthenticationRequest::new
);
this.realms = realms;
}
Expand All @@ -58,15 +56,17 @@ protected void doExecute(
List<OpenIdConnectRealm> matchingRealms = this.realms.stream()
.filter(r -> r instanceof OpenIdConnectRealm && ((OpenIdConnectRealm) r).isIssuerValid(request.getIssuer()))
.map(r -> (OpenIdConnectRealm) r)
.collect(Collectors.toList());
.toList();
if (matchingRealms.isEmpty()) {
listener.onFailure(
new ElasticsearchSecurityException("Cannot find OpenID Connect realm with issuer [{}]", request.getIssuer())
);
return;
} else if (matchingRealms.size() > 1) {
listener.onFailure(
new ElasticsearchSecurityException("Found multiple OpenID Connect realm with issuer [{}]", request.getIssuer())
);
return;
} else {
realm = matchingRealms.get(0);
}
Expand Down

0 comments on commit 02e0c8f

Please sign in to comment.