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

Passing empty string to "notBefore" and "expiresIn" option gives non-standard error #499

Open
MitMaro opened this issue Jun 26, 2018 · 0 comments

Comments

@MitMaro
Copy link
Contributor

MitMaro commented Jun 26, 2018

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

What

When passing an empty string to "notBefore". it throws a val is not a non-empty string or a valid number. val="" from the ms library. I would expect this to throw '"notBefore" should be a number of seconds or string representing a timespan' which is the same error as other invalid inputs.

Test Case

const jwt = require('jsonwebtoken');
jwt.sign({}, undefined, {
  algorithm: 'none',
  notBefore: ''
});

Expected Output

/home/mitmaro/jwt-test/node_modules/jsonwebtoken/sign.js:98
throw err;
^

Error: "notBefore" should be a number of seconds or string representing a timespan eg: "1d", "20h", 60
at Object.module.exports [as sign] (/home/mitmaro/jwt-test/node_modules/jsonwebtoken/sign.js:153:22)
at Object.<anonymous> (/home/mitmaro/jwt-test/test.js:2:5)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3

Actual Output

/home/mitmaro/test/node_modules/jsonwebtoken/node_modules/ms/index.js:34
throw new Error(
^

Error: val is not a non-empty string or a valid number. val=""
at module.exports (/home/mitmaro/jwt-test/node_modules/jsonwebtoken/node_modules/ms/index.js:34:9)
at module.exports (/home/mitmaro/jwt-test/node_modules/jsonwebtoken/lib/timespan.js:7:24)
at Object.module.exports [as sign] (/home/mitmaro/jwt-test/node_modules/jsonwebtoken/sign.js:151:19)
at Object.<anonymous> (/home/mitmaro/jwt-test/test.js:2:5)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
@MitMaro MitMaro changed the title Passing empty string to "notBefore" option gives non-standard error Passing empty string to "notBefore" and "expiresIn" option gives non-standard error Jun 26, 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

1 participant