Conversation
| } | ||
|
|
||
| // Apply deferred settings | ||
| client.setLoggingEnabled(loggingEnabled); |
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 days ago
In general, the fix is to stop calling the deprecated AuthAPI.setLoggingEnabled(boolean) method and instead configure logging using the non-deprecated mechanism provided by the Auth0 Java SDK. In recent versions, HTTP/logging behavior is configured via HttpOptions rather than on AuthAPI directly, so the correct approach is to ensure that an HttpOptions instance with the desired logging configuration is supplied to the AuthAPI constructor.
Within RequestProcessor.createClientForDomain, the behavior today is:
- If
httpOptionsis non-null, use it to build theAuthAPI. - Otherwise, create an
AuthAPIwith the 3-arg constructor. - Then, regardless, call
client.setLoggingEnabled(loggingEnabled).
To preserve behavior without using the deprecated method, we can:
- When
httpOptionsis null, create a newHttpOptionsinstance and set its logging flag according tologgingEnabled, then pass it into the 4-argAuthAPIconstructor. - When
httpOptionsis non-null, derive a newHttpOptions(or mutate the existing one if that is acceptable in this context) with the logging flag set based onloggingEnabled, and then pass that into the constructor. - Remove the direct call to
client.setLoggingEnabled(loggingEnabled)entirely.
Because we cannot assume other parts of the code, we will keep the logic local and simple: if httpOptions is null, we create a fresh HttpOptions and configure logging; if it is not null, we reuse it and simply set logging on it before using it. This preserves existing semantics (a single HttpOptions object shared across clients, if that is what the rest of the code expects) while routing logging configuration through the non-deprecated HttpOptions API. No new imports are needed because HttpOptions is already imported.
Concretely, in createClientForDomain:
- Introduce a local variable
HttpOptions localHttpOptionsthat is either the existinghttpOptionsor a new one. - Set logging on
localHttpOptionsaccording tologgingEnabled. - Always use the 4-arg
AuthAPIconstructor withlocalHttpOptions. - Remove line 179:
client.setLoggingEnabled(loggingEnabled);.
| @@ -169,14 +169,15 @@ | ||
| AuthAPI createClientForDomain(String domain) { | ||
| final AuthAPI client; | ||
|
|
||
| if (httpOptions != null) { | ||
| client = new AuthAPI(domain, clientId, clientSecret, httpOptions); | ||
| } else { | ||
| client = new AuthAPI(domain, clientId, clientSecret); | ||
| HttpOptions localHttpOptions = httpOptions; | ||
| if (localHttpOptions == null) { | ||
| localHttpOptions = new HttpOptions(); | ||
| } | ||
| localHttpOptions.setLogging(loggingEnabled); | ||
|
|
||
| client = new AuthAPI(domain, clientId, clientSecret, localHttpOptions); | ||
|
|
||
| // Apply deferred settings | ||
| client.setLoggingEnabled(loggingEnabled); | ||
| if (telemetryDisabled) { | ||
| client.doNotSendTelemetry(); | ||
| } else { |
| this.signatureVerifier = signatureVerifier; | ||
| } | ||
|
|
||
| // Builder(AuthAPI client, String responseType, IdTokenVerifier.Options verifyOptions) { |
There was a problem hiding this comment.
Is commenting this piece of code intended?
| String originDomain = domainProvider.getDomain(request); | ||
| AuthAPI client = createClientForDomain(originDomain); | ||
| String originIssuer = getIssuer(originDomain); | ||
| verifyOptions.setIssuer(originIssuer); |
There was a problem hiding this comment.
Can this cause issues? Similar to how Domain was causing issues?
Looks like the verifyOptions is tied to the RequestProcessor instance that is created during init using the AuthenticationController.
If we modify the verifyOptions in-flight, will it cause problems when multiple calls are happening, since this is a common instance across?
Need to verify this once.
There was a problem hiding this comment.
Yes, that's correct I have updated verifyOptions
| return new Tokens(accessToken, idToken, refreshToken, type, expiresIn); | ||
| } | ||
|
|
||
| private String getIssuer(String domain) { |
There was a problem hiding this comment.
Minor suggestion, since we are actually constructing the Issuer here, we can name this better. Something like ToIssuer()?
Also, consider moving this to a Utils class?
There was a problem hiding this comment.
Have renamed to constructIssuer
There was a problem hiding this comment.
Is this change intended? There already is a test folder.
If yes, it would be easier if some detail is added as to what we are trying to test
There was a problem hiding this comment.
I have added a note.. before merging will remove the test and docker file
| return new Tokens(request.getParameter(KEY_ACCESS_TOKEN), request.getParameter(KEY_ID_TOKEN), null, request.getParameter(KEY_TOKEN_TYPE), expiresIn); | ||
| private Tokens getFrontChannelTokens(HttpServletRequest request, String originDomain, String originIssuer) { | ||
| Long expiresIn = request.getParameter(KEY_EXPIRES_IN) == null ? null | ||
| : Long.parseLong(request.getParameter(KEY_EXPIRES_IN)); |
Check notice
Code scanning / CodeQL
Missing catch of NumberFormatException Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 days ago
In general, the fix is to ensure that parsing the expires_in request parameter into a Long does not allow a NumberFormatException to propagate unchecked. This is best achieved by surrounding the Long.parseLong(...) call with a try/catch that handles NumberFormatException and falls back to a safe behavior (e.g., treating the value as absent) or, if appropriate, wrapping it in a domain-specific exception.
The single best way to fix this, without changing existing functionality for valid inputs, is to catch NumberFormatException inside getFrontChannelTokens. When KEY_EXPIRES_IN is present but not parseable as a Long, the behavior that least surprises callers is to treat it the same as if the parameter were missing and set expiresIn to null. That keeps the method’s signature and returned Tokens construction unchanged while making it robust against malformed client input. Concretely, in src/main/java/com/auth0/RequestProcessor.java, adjust lines 475–479 so that the computation of expiresIn is enclosed in a try/catch (NumberFormatException e) that sets expiresIn to null on failure, then pass that expiresIn to the Tokens constructor as before. No new imports or methods are required, as NumberFormatException is in java.lang.
| @@ -473,8 +473,15 @@ | ||
| * parameters. | ||
| */ | ||
| private Tokens getFrontChannelTokens(HttpServletRequest request, String originDomain, String originIssuer) { | ||
| Long expiresIn = request.getParameter(KEY_EXPIRES_IN) == null ? null | ||
| : Long.parseLong(request.getParameter(KEY_EXPIRES_IN)); | ||
| Long expiresIn = null; | ||
| String expiresInParam = request.getParameter(KEY_EXPIRES_IN); | ||
| if (expiresInParam != null) { | ||
| try { | ||
| expiresIn = Long.parseLong(expiresInParam); | ||
| } catch (NumberFormatException ignored) { | ||
| expiresIn = null; | ||
| } | ||
| } | ||
| return new Tokens(request.getParameter(KEY_ACCESS_TOKEN), request.getParameter(KEY_ID_TOKEN), null, | ||
| request.getParameter(KEY_TOKEN_TYPE), expiresIn, originDomain, originIssuer); | ||
| } |
| assertThat(signatureVerifier, is(notNullValue())); | ||
| assertThat(signatureVerifier, instanceOf(AlgorithmNameVerifier.class)); | ||
| assertThat(verificationOptions, is(controller.getRequestProcessor().verifyOptions)); | ||
| Tokens result = controller.handle(request); |
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation Note test
Copilot Autofix
AI 4 days ago
Copilot could not generate an autofix suggestion
Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.
|
|
||
| NullPointerException exception = assertThrows( | ||
| NullPointerException.class, | ||
| () -> controller.handle((HttpServletRequest) null)); |
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation Note test
Copilot Autofix
AI 4 days ago
Copilot could not generate an autofix suggestion
Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.
| assertThat(requestProcessor.verifyOptions.clock, is(nullValue())); | ||
| assertThat(requestProcessor.verifyOptions.nonce, is(nullValue())); | ||
| assertThat(requestProcessor.verifyOptions.getMaxAge(), is(nullValue())); | ||
| AuthorizeUrl result = controller.buildAuthorizeUrl(request, redirectUri); |
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation Note test
Copilot Autofix
AI 4 days ago
Copilot could not generate an autofix suggestion
Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.
| assertThat(requestProcessor.verifyOptions.clockSkew, is(12345)); | ||
| NullPointerException exception = assertThrows( | ||
| NullPointerException.class, | ||
| () -> controller.buildAuthorizeUrl(null, "https://redirect.to/me")); |
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation Note test
Copilot Autofix
AI 4 days ago
Copilot could not generate an autofix suggestion
Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.
| assertThat(requestProcessor.verifyOptions.getMaxAge(), is(12345)); | ||
| NullPointerException exception = assertThrows( | ||
| NullPointerException.class, | ||
| () -> controller.buildAuthorizeUrl(request, (String) null)); |
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation Note test
Copilot Autofix
AI 4 days ago
Copilot could not generate an autofix suggestion
Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.
| assertThat(exception.getCode(), is("access_denied")); | ||
| // Note: getDescription() is deprecated but still available | ||
| @SuppressWarnings("deprecation") | ||
| String description = exception.getDescription(); |
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation Note test
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 days ago
To fix the problem, the test should stop invoking the deprecated InvalidRequestException.getDescription() method and instead use the non-deprecated accessor that exposes the same error description. In most Auth0 Java APIs, InvalidRequestException (or similar OAuth error exception classes) provide a getErrorDescription() method that replaces getDescription(). The test should assert against this new accessor rather than the deprecated one. This removes the need for @SuppressWarnings("deprecation") and resolves the CodeQL finding while preserving the assertion on the error description.
Concretely, in src/test/java/com/auth0/RequestProcessorTest.java, within the shouldThrowExceptionWhenErrorInRequest test (around lines 381–396), remove the comment and the @SuppressWarnings("deprecation") annotation that justify using the deprecated method, replace the call to exception.getDescription() with exception.getErrorDescription(), and keep the assertion checking that the description equals "The user denied the request". No other parts of the test need to change, and no new imports are required.
| @@ -389,9 +389,7 @@ | ||
| () -> processor.process(request, response)); | ||
|
|
||
| assertThat(exception.getCode(), is("access_denied")); | ||
| // Note: getDescription() is deprecated but still available | ||
| @SuppressWarnings("deprecation") | ||
| String description = exception.getDescription(); | ||
| String description = exception.getErrorDescription(); | ||
| assertThat(description, is("The user denied the request")); | ||
| } | ||
|
|
Changes
Please describe both what is changing and why this is important. Include:
References
Please include relevant links supporting this change such as a:
Testing
Please describe how this can be tested by reviewers. Be specific about anything not tested and reasons why. If this library has unit and/or integration testing, tests should be added for new functionality and existing tests should complete without errors.
Checklist