Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MitMaro opened this issue Jun 26, 2018 · 1 comment
Open

Comments

@MitMaro
Copy link
Contributor

MitMaro commented Jun 26, 2018

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
}
@MitMaro MitMaro changed the title -Infinity, Infinity and NaN do not fail "nbf" claim validation -Infinity, Infinity and NaN do not fail "nbf" claim validation Jun 26, 2018
@MitMaro MitMaro changed the title -Infinity, Infinity and NaN do not fail "nbf" claim validation -Infinity, Infinity and NaN do not fail "nbf" and "exp" claim validation Jun 26, 2018
@andrewnester
Copy link
Contributor

Hi! I just created PR fixing this: #532

andrewnester added a commit to andrewnester/node-jsonwebtoken that referenced this issue Oct 17, 2018
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

No branches or pull requests

2 participants