Skip to content

-Infinity, Infinity and NaN do not fail "nbf" and "exp" claim validation #500

Open
@MitMaro

Description

@MitMaro

This was an issue found during the work I did for #497.

What

Passing -Infinity, Infinity and NaN for nbf in the payload is not caught by the claim validation. Since these values all JSON.stringify to null, they should be treated similar to passing null to nbf.

Test Case

const jwt = require('jsonwebtoken');
console.log(jwt.sign({nbf: Infinity}, undefined, {algorithm: 'none'}));
console.log(jwt.sign({nbf: -Infinity}, undefined, {algorithm: 'none'}));
console.log(jwt.sign({nbf: NaN}, undefined, {algorithm: 'none'}));

Expected Output

Error with message "nbf" should be a number of seconds for each sign call.

Actual Output

eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJuYmYiOm51bGwsImlhdCI6MTUzMDAzMTcxM30.
eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJuYmYiOm51bGwsImlhdCI6MTUzMDAzMTcxM30.
eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJuYmYiOm51bGwsImlhdCI6MTUzMDAzMTcxM30.

Which decodes as:

{
  "nbf": null,
  "iat": 1530031713
}

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