Skip to content

Unhandled NPE with alg:none JWT in Bearer Authentication#48798

Open
mabartos wants to merge 1 commit intokeycloak:mainfrom
mabartos:KC-48744
Open

Unhandled NPE with alg:none JWT in Bearer Authentication#48798
mabartos wants to merge 1 commit intokeycloak:mainfrom
mabartos:KC-48744

Conversation

@mabartos
Copy link
Copy Markdown
Member

@mabartos mabartos commented May 7, 2026

Closes keycloak#48744

Signed-off-by: Martin Bartoš <mabartos@redhat.com>
@mabartos mabartos requested a review from a team as a code owner May 7, 2026 13:26
@mabartos mabartos requested a review from a team May 7, 2026 13:41
@mabartos mabartos self-assigned this May 7, 2026
Copy link
Copy Markdown
Contributor

@rmartinc rmartinc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mabartos! LGTM! Just a minor change for the test. I think that creating a normal none token is better. You can see other tests that are doing this.

Comment on lines +23 to +24
private static final String ALG_NONE_TOKEN =
"eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJzdWIiOiJhdHRhY2tlciIsImV4cCI6OTk5OTk5OTk5OX0.";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Input validation/ Unhandled NullPointerException on alg:none JWT in Bearer Authentication

2 participants