You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polaris.apache.org by "TomerHeber (via GitHub)" <gi...@apache.org> on 2024/09/17 01:09:14 UTC

[I] [BUG] expired JWT token return 5xx instead of 401 [polaris]

TomerHeber opened a new issue, #304:
URL: https://github.com/apache/polaris/issues/304

   ### Is this a possible security vulnerability?
   
   - [X] This is NOT a possible security vulnerability
   
   ### Describe the bug
   
   When sending an http request with an expired token, 5xx is returned instead of 401.
   
   ### To Reproduce
   
   1. Enable JWTBroker.
   2. Generate a token with credentials.
   3. Wait 60 minutes.
   4. Send a request with the expired token. Returns 5xx instead of 401.
   
   ```
   oauth2:
     # type: test
     type: default
     tokenBroker:
       type: symmetric-key
       secret: polaris
   
   authenticator:
     # class: org.apache.polaris.service.auth.TestInlineBearerTokenPolarisAuthenticator
     class: org.apache.polaris.service.auth.DefaultPolarisAuthenticator
     tokenBroker:
       type: symmetric-key
       secret: polaris
   ```
   
   ### Actual Behavior
   
   5xx http response.
   
   ### Expected Behavior
   
   401 http reposne.
   
   ### Additional context
   
   The issue is with this code snippet:
   https://github.com/apache/polaris/blob/main/polaris-service/src/main/java/org/apache/polaris/service/auth/JWTBroker.java#L59
   ```
    JWTVerifier verifier = JWT.require(getAlgorithm()).build();
     DecodedJWT decodedJWT = verifier.verify(token);
     Boolean isActive = decodedJWT.getClaim(CLAIM_KEY_ACTIVE).asBoolean();
     if (isActive == null || !isActive) {
         throw new NotAuthorizedException("Token is not active");
       }
       if (decodedJWT.getExpiresAtAsInstant().isBefore(Instant.now())) {
         throw new NotAuthorizedException("Token has expired");
       }
   ```
   
   verifier.verify throws `JWTVerificationException` if the token verification fails (including expired token).
   https://github.com/auth0/java-jwt/blob/fb6d00ad9773c6e7624c518feb2d06ed191287fa/lib/src/main/java/com/auth0/jwt/JWTVerifier.java#L346
   
   This is an uncaught exception.
   The exception `NotAuthorizedException` should have been returned instead.
   
   
   
   ### System information
   
   N/A


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@polaris.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [BUG] expired JWT token returns 5xx instead of 401 [polaris]

Posted by "TomerHeber (via GitHub)" <gi...@apache.org>.
TomerHeber commented on issue #304:
URL: https://github.com/apache/polaris/issues/304#issuecomment-2354312586

   Consider using the decode function instead:
   https://javadoc.io/doc/com.auth0/java-jwt/latest/com/auth0/jwt/JWT.html


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [BUG] expired JWT token returns 5xx instead of 401 [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard closed issue #304: [BUG] expired JWT token returns 5xx instead of 401
URL: https://github.com/apache/polaris/issues/304


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [BUG] expired JWT token returns 5xx instead of 401 [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on issue #304:
URL: https://github.com/apache/polaris/issues/304#issuecomment-2457915971

   Should be fixed by #530, but please re-open if that's not the case


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org