eclipse-vertx / vertx-auth

Apache License 2.0
166 stars 156 forks source link

NullPointerException in private Constructor of OAuth2AuthHandlerImpl #606

Closed fbuetler closed 1 year ago

fbuetler commented 1 year ago

Version

I encountered the issue with vertx-auth-oauth2 4.3.7 but also with the latest master commit.

Context

I encountered a NullPointerException while using the following code snippet:

final OAuth2AuthHandler authHandler = OAuth2AuthHandler.create(vertx, authProvider, callbackURL)
        .setupCallback(callback)
        .extraParams(responseModeParam)
        .withScope(sessionScope);

The withScope call triggers the creation of a new OAuth2AuthHandlerImpl with a private constructor. Note, that some extraParams are set beforehand. In the private constructor the extraParams are copied, but obviously trigger a NullPointerException:

// state copy
    if (base.extraParams != null) {
      extraParams = extraParams.copy();
    }

Start of the stack trace:

20:03:39.348 [vert.x-eventloop-thread-0] ERROR io.vertx.core.impl.ContextBase - Unhandled exception
java.lang.NullPointerException: null
        at io.vertx.ext.web.handler.impl.OAuth2AuthHandlerImpl.<init>(OAuth2AuthHandlerImpl.java:111)
        at io.vertx.ext.web.handler.impl.OAuth2AuthHandlerImpl.withScope(OAuth2AuthHandlerImpl.java:244)

Proposed Fix

// state copy
    if (base.extraParams != null) {
      extraParams = base.extraParams.copy();
    }

Mitigation

Put the extraParams() at the end such that the path triggering the Exception in the private constructor is not used.

fbuetler commented 1 year ago

My bad, wrong repo. Moved to vertx-web