Skip to content

Commit

Permalink
SECURITY-3227
Browse files Browse the repository at this point in the history
(cherry picked from commit 907382d)
  • Loading branch information
timja authored and daniel-beck committed Sep 5, 2023
1 parent bb34272 commit 545b115
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
import java.net.Proxy;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
Expand All @@ -108,7 +109,7 @@ public class AzureSecurityRealm extends SecurityRealm {
private static final String TIMESTAMP_ATTRIBUTE = AzureSecurityRealm.class.getName() + ".beginTime";
private static final String NONCE_ATTRIBUTE = AzureSecurityRealm.class.getName() + ".nonce";
private static final Logger LOGGER = Logger.getLogger(AzureSecurityRealm.class.getName());
private static final int NONCE_LENGTH = 10;
private static final int NONCE_LENGTH = 16;
public static final String CALLBACK_URL = "/securityRealm/finishLogin";
private static final String CONVERTER_NODE_CLIENT_ID = "clientid";
private static final String CONVERTER_NODE_CLIENT_SECRET = "clientsecret";
Expand Down Expand Up @@ -458,7 +459,12 @@ public HttpResponse doFinishLogin(StaplerRequest request)
JwtClaims validateIdToken(String expectedNonce, String idToken) throws InvalidJwtException {
JwtClaims claims = getJwtConsumer().processToClaims(idToken);
final String responseNonce = (String) claims.getClaimValue("nonce");
if (StringUtils.isAnyEmpty(expectedNonce, responseNonce) || !expectedNonce.equals(responseNonce)) {
if (StringUtils.isAnyEmpty(expectedNonce, responseNonce)
|| !MessageDigest.isEqual(
expectedNonce.getBytes(StandardCharsets.UTF_8),
responseNonce.getBytes(StandardCharsets.UTF_8)
)
) {
throw new IllegalStateException(String.format("Invalid nonce in the response, "
+ "expected: %s actual: %s", expectedNonce, responseNonce));
}
Expand Down

0 comments on commit 545b115

Please sign in to comment.