Skip to content

Commit

Permalink
fix: allow any JSON numeric value for timestamp values
Browse files Browse the repository at this point in the history
> NumericDate
>    A JSON numeric value representing the number of seconds from
>    1970-01-01T00:00:00Z UTC until the specified UTC date/time,
>    ignoring leap seconds.  This is equivalent to the IEEE Std 1003.1,
>    2013 Edition [POSIX.1] definition "Seconds Since the Epoch", in
>    which each day is accounted for by exactly 86400 seconds, other
>    than that non-integer values can be represented.  See RFC 3339
>    [RFC3339] for details regarding date/times in general and UTC in
>    particular.
  • Loading branch information
panva committed Jun 1, 2020
1 parent b50d695 commit 7ba4922
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/jwt/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const isTimestamp = (value, label, required = false) => {
throw new JWTClaimInvalid(`"${label}" claim is missing`, label, 'missing')
}

if (value !== undefined && (typeof value !== 'number' || !Number.isSafeInteger(value))) {
throw new JWTClaimInvalid(`"${label}" claim must be a unix timestamp`, label, 'invalid')
if (value !== undefined && (typeof value !== 'number')) {
throw new JWTClaimInvalid(`"${label}" claim must be a JSON numeric value`, label, 'invalid')
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/jwt/verify.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ test('options.ignoreIat & options.maxTokenAge may not be used together', t => {
const err = t.throws(() => {
const invalid = JWS.sign({ [claim]: val }, key)
JWT.verify(invalid, key)
}, { instanceOf: errors.JWTClaimInvalid, message: `"${claim}" claim must be a unix timestamp` })
}, { instanceOf: errors.JWTClaimInvalid, message: `"${claim}" claim must be a JSON numeric value` })

t.is(err.claim, claim)
t.is(err.reason, 'invalid')
Expand Down

0 comments on commit 7ba4922

Please sign in to comment.