Skip to content

IAT payload value is not respected if value is zero #874

Description

@mglubb

Description

If the iat payload value is is zero, in other words, the UNIX epoch, it is not respected and the current time is used instead. I believe it is because zero evaluates to false here:

https://github.com/auth0/node-jsonwebtoken/blob/master/sign.js#L179

Reproduction

jwt.sign({ iat: 0, data: 'foobar' }, 'secret', { expiresIn: 86400 });

Expected payload iat value should be zero and exp is expected to be 86400. The actual iat value is the current time and exp is the current time plus 86400.

Environment

  • Version: 9.0.0
  • Node v14.18.1 (npm v8.12.2)

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