Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix][broker] Support OIDC providers with JWK without alg field set in keys #22421

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ private CompletableFuture<DecodedJWT> authenticateToken(String token) {
return verifyIssuerAndGetJwk(jwt)
.thenCompose(jwk -> {
try {
if (!jwt.getAlgorithm().equals(jwk.getAlgorithm())) {
// verify the algorithm, if it is set ("alg" is optional in the JWK spec)
if (jwk.getAlgorithm() != null && !jwt.getAlgorithm().equals(jwk.getAlgorithm())) {
incrementFailureMetric(AuthenticationExceptionCode.ALGORITHM_MISMATCH);
return CompletableFuture.failedFuture(
new AuthenticationException("JWK's alg [" + jwk.getAlgorithm()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class AuthenticationProviderOpenIDIntegrationTest {
// These are the kid values for JWKs in the /keys endpoint
String validJwk = "valid";
String invalidJwk = "invalid";
String validJwkWithoutAlg = "valid_without_alg";

// The valid issuer
String issuer;
Expand Down Expand Up @@ -188,10 +189,16 @@ void beforeClass() throws IOException {
"kty":"RSA",
"n":"invalid-key",
"e":"AQAB"
},
{
"kid":"%s",
"kty":"RSA",
"n":"%s",
"e":"%s"
}
]
}
""".formatted(validJwk, n, e, invalidJwk))));
""".formatted(validJwk, n, e, invalidJwk, validJwkWithoutAlg, n, e))));

server.stubFor(
get(urlEqualTo("/missing-kid/.well-known/openid-configuration"))
Expand Down Expand Up @@ -275,6 +282,14 @@ public void testTokenWithValidJWK() throws Exception {
assertEquals(role, provider.authenticateAsync(new AuthenticationDataCommand(token)).get());
}

@Test
public void testTokenWithValidJWKWithoutAlg() throws Exception {
String role = "superuser";
// test with a key in JWK that does not have an "alg" field. "alg" is optional in the JWK spec
String token = generateToken(validJwkWithoutAlg, issuer, role, "allowed-audience", 0L, 0L, 10000L);
assertEquals(role, provider.authenticateAsync(new AuthenticationDataCommand(token)).get());
}

@Test
public void testTokenWithTrailingSlashAndValidJWK() throws Exception {
String role = "superuser";
Expand Down
Loading