Unhandled NPE with alg:none JWT in Bearer Authentication#48798
Open
mabartos wants to merge 1 commit intokeycloak:mainfrom
Open
Unhandled NPE with alg:none JWT in Bearer Authentication#48798mabartos wants to merge 1 commit intokeycloak:mainfrom
mabartos wants to merge 1 commit intokeycloak:mainfrom
Conversation
Member
mabartos
commented
May 7, 2026
- Closes Input validation/ Unhandled NullPointerException on alg:none JWT in Bearer Authentication #48744
- just check if the SignatureProvider is not null
- Abstract test class for util tests requiring a Keycloak session
Closes keycloak#48744 Signed-off-by: Martin Bartoš <mabartos@redhat.com>
rmartinc
requested changes
May 8, 2026
Comment on lines
+23
to
+24
| private static final String ALG_NONE_TOKEN = | ||
| "eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJzdWIiOiJhdHRhY2tlciIsImV4cCI6OTk5OTk5OTk5OX0."; |
Contributor
There was a problem hiding this comment.
Instead of this you can create a none token normally. Check for example AbstractBaseClientAuthTest that tests a none token:
@Test
public void userInfoRejectsAlgNoneToken() {
JsonWebToken jwt = createDefaultToken();
String noneRequest = new JWSBuilder().jsonContent(jwt).none();
UserInfoResponse response = oauth.doUserInfoRequest(noneRequest);
assertEquals(401, response.getStatusCode());
assertFalse(response.isSuccess());
assertEquals(OAuthErrorException.INVALID_TOKEN, response.getError());
}
protected JsonWebToken createDefaultToken() {
JsonWebToken token = new JsonWebToken();
token.id(SecretGenerator.getInstance().generateSecureID());
token.issuer("http://127.0.0.1:8500");
token.audience(oauth.getEndpoints().getIssuer());
token.iat((long) Time.currentTime());
token.exp((long) (Time.currentTime() + 300));
token.subject("attacker");
return token;
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.