Skip to content

Allow a leeway to be given for the iat claim verification - #747

Open
denis1011101 wants to merge 1 commit into
jwt:mainfrom
denis1011101:add-iat-leeway
Open

Allow a leeway to be given for the iat claim verification#747
denis1011101 wants to merge 1 commit into
jwt:mainfrom
denis1011101:add-iat-leeway

Conversation

@denis1011101

Copy link
Copy Markdown

Adds an optional leeway to the iat verification. Refs #353.

Right now iat is compared exactly against the local clock, so a token gets
rejected as soon as the issuer's clock is slightly ahead of the verifier's.
There's no way to allow for that: the global leeway doesn't apply to this
claim, and iat_leeway was dropped in 2.2.0.

In #353 (comment) anakinj
suggested keeping the comparison exact and letting the caller say how much drift
is acceptable, so that's what this does:

JWT.decode(token, secret, true, verify_iat: { leeway: 30 }, algorithm: 'HS256')
JWT::Claims.verify_payload!(payload, iat: { leeway: 30 })

It defaults to 0, so nothing changes for existing code. The value is read from
the claim's own options, as in that comment, which keeps the old iat_leeway
name out of the API.

Refs rather than Closes, since the default behaviour stays as it was.

Checklist

Before the PR can be merged be sure the following are checked:

  • There are tests for the fix or feature added/changed
  • A description of the changes and a reference to the PR has been added to CHANGELOG.md. More details in the CONTRIBUTING.md

The iat claim is verified with an exact comparison against the local
clock, so a token is rejected whenever the clock of the issuer is even
marginally ahead of the clock of the verifier. There was no way to
tolerate that drift: the global leeway option does not apply to this
claim and iat_leeway was removed in 2.2.0.

Accept a leeway for the claim, defaulting to 0 so that the current
behaviour is unchanged, and keep the comparison exact:

  JWT.decode(token, secret, true, verify_iat: { leeway: 30 })
  JWT::Claims.verify_payload!(payload, iat: { leeway: 30 })

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant