Conversation
| 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 24 days ago
In general, the problem is fixed by surrounding the numeric parsing operation with a try/catch for NumberFormatException, or by validating that the string is numeric before parsing, and then deciding how to handle invalid input (e.g., logging, defaulting to null, or rejecting the request). For this specific method, the best non-invasive behavior is: keep returning the same expiresIn value when parsing succeeds, and when parsing fails, treat it as if no expires_in was provided (i.e., set expiresIn to null), which avoids throwing while not changing the behavior of valid requests.
Concretely, in src/main/java/com/auth0/RequestProcessor.java, within getFrontChannelTokens, we should replace the direct ternary call to Long.parseLong(...) with a small block that (1) reads the parameter into a local String, (2) attempts to parse it inside a try block, (3) catches NumberFormatException and sets expiresIn to null. No new imports are needed because NumberFormatException is in java.lang. The rest of the method remains unchanged, still passing expiresIn into the Tokens constructor.
| @@ -404,8 +404,16 @@ | ||
| * 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)); | ||
| String expiresInParam = request.getParameter(KEY_EXPIRES_IN); | ||
| Long expiresIn = null; | ||
| if (expiresInParam != null) { | ||
| try { | ||
| expiresIn = Long.parseLong(expiresInParam); | ||
| } catch (NumberFormatException ignored) { | ||
| // If the expires_in parameter is not a valid number, ignore it and treat as unspecified. | ||
| expiresIn = null; | ||
| } | ||
| } | ||
| return new Tokens(request.getParameter(KEY_ACCESS_TOKEN), request.getParameter(KEY_ID_TOKEN), null, | ||
| request.getParameter(KEY_TOKEN_TYPE), expiresIn, originDomain, originIssuer); | ||
| } |
…a-mvc-common into feat/mcd-support
Summary
DomainResolverinterface for dynamic domain resolution, alongside the existing static domain modeSignedCookieUtils), preventing tampering between the authorize and callback phasesTokensobject withdomainandissuerfields so callers know which tenant issued the tokensRequestProcessorwhere shared mutableIdTokenVerifier.Optionscould cause incorrect nonce validation under concurrent requests, verification options are now created per-requestNew Public API
DomainResolverinterfaceString resolve(HttpServletRequest)user-provided function to resolve Auth0 domain per requestAuthenticationController.newBuilder(DomainResolver, clientId, clientSecret)Tokens.getDomain()/Tokens.getIssuer()Internal Changes
RequestProcessorAuthAPIclient to per-request client creation viaDomainProviderabstraction. Verification options now created per-request for thread safety.AuthorizeUrlorigin_domaincookie duringbuild()/ fromPushedAuthorizationRequest()`TransientCookieStorestoreSignedOriginDomain()/getSignedOriginDomain()methods for HMAC cookie lifecycleSignedCookieUtils(new)IdTokenVerifier.OptionsDomainProvider/StaticDomainProvider/ResolverDomainProviderBackward Compatibility
newBuilder(domain, clientId, clientSecret)continues to work unchangedTesting
SignedCookieUtilsTest— HMAC signing, verification, and tampering detectionAuthenticationControllerTest— covers static domain, resolver-based domain, builder validation (mutual exclusivity of domain/resolver), cookie path, organization, invitationRequestProcessorTest— per-request client creation, domain resolution, HMAC cookie round-trip, token enrichment with domain/issuer, state/nonce validation across both storage modesTransientCookieStoreTest— signed origin domain cookie storage and retrievalTokensTest— new domain/issuer fields