Skip to content

ApiClient.verify() accepts tokens up to ~16 minutes after expiry (acceptLeeway(1000) is in seconds) #467

Backlog

Description

@hackermengzhi

Version

18.5.0 (master at 41a050c), java-jwt 4.4.0

Summary

ApiClient.verify() builds its verifier with a leeway of 1000:

https://github.com/XeroAPI/Xero-Java/blob/41a050c/src/main/java/com/xero/api/ApiClient.java#L197-L200

JWTVerifier verifier = JWT.require(algorithm)
        .withIssuer("https://identity.xero.com")
        .acceptLeeway(1000)
        .build();

In java-jwt, acceptLeeway(long) takes seconds, not milliseconds. So exp, nbf and iat are all checked with a 16 min 40 s tolerance. The README calls defaultClient.verify(tokenResponse.getAccessToken()) after token exchange and refresh. An app that relies on that check to reject a stale access token will treat it as valid for up to ~16 minutes after it has expired.

For comparison, xero-node uses a default clock tolerance of 5 seconds.

Steps to reproduce

Sign tokens with a local RSA key and verify them with the same builder configuration as verify():

String token = JWT.create().withIssuer("https://identity.xero.com")
    .withExpiresAt(new Date(System.currentTimeMillis() - minutes * 60_000L)).sign(signer);

JWT.require(Algorithm.RSA256(publicKey, null))
    .withIssuer("https://identity.xero.com")
    .acceptLeeway(1000)
    .build()
    .verify(token);
expired 10 min ago -> ACCEPTED
expired 16 min ago -> ACCEPTED
expired 17 min ago -> rejected (TokenExpiredException)

Expected

Expired tokens are rejected, allowing only a few seconds of clock skew.

Suggested fix

.acceptLeeway(5)

or make the leeway configurable on ApiClient with a small default.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions