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

Signing a payload with a iat results in an invalid nbf value #435

Closed
MitMaro opened this issue Dec 21, 2017 · 2 comments
Closed

Signing a payload with a iat results in an invalid nbf value #435

MitMaro opened this issue Dec 21, 2017 · 2 comments
Labels

Comments

@MitMaro
Copy link
Contributor

MitMaro commented Dec 21, 2017

Related Issue: #142


Problem Description

The calculation of payload.nbf does not use payload.iat when notBefore is passed an offset, and instead the current time is always used.

Expected

In this case I would expect that the payload.nbf value to be an offset based on the passed payload.iat. This would be consistent with payload.exp.

Reduced Test Case

const {sign, decode} = require('jsonwebtoken');
const token = sign({foo: 'bar', iat: 100}, 'secret', {notBefore: '-1s'});
const decoded = decode(token);
console.log(`Expecting nbf value ${decoded.nbf} to equal 99`);
> Expecting nbf value 1513884708 to equal 99

Investigation

It seems that the timestamp is not passed to timespan function on Line 148 of sign.js similar to how it is passed to the call on Line 155 of sign.js.

@MitMaro
Copy link
Contributor Author

MitMaro commented Dec 21, 2017

I would be willing to put up a PR fixing the issue with tests if this is not by design.

@ziluvatar
Copy link
Contributor

@MitMaro I think this simply wasn't fixed when the timestamp was introduced for exp. #217. Be free to send a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants