-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix signing method with sealed objects, do not modify the params obje…
…ct. closes #147
- Loading branch information
1 parent
42145bc
commit be9c09a
Showing
4 changed files
with
18 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
var jws = require('jws'); | ||
var ms = require('ms'); | ||
var timespan = require('./lib/timespan'); | ||
var xtend = require('xtend'); | ||
|
||
var JWT = module.exports; | ||
|
||
|
@@ -39,7 +40,7 @@ JWT.decode = function (jwt, options) { | |
|
||
JWT.sign = function(payload, secretOrPrivateKey, options, callback) { | ||
options = options || {}; | ||
|
||
payload = typeof payload === 'object' ? xtend(payload) : payload; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jfromaniello
Author
Member
|
||
var header = {}; | ||
|
||
if (typeof payload === 'object') { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
var jwt = require('../index'); | ||
var expect = require('chai').expect; | ||
|
||
describe('signing with a sealed payload', function() { | ||
|
||
it('should put the expiration claim', function () { | ||
var token = jwt.sign(Object.seal({foo: 123}), '123', { expiresIn: 10 }); | ||
var result = jwt.verify(token, '123'); | ||
expect(result.exp).to.be.closeTo(Math.floor(Date.now() / 1000) + 10, 0.2); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For whatever its worth, this turned out to be a breaking change for my application. It was relying on the modification of the payload, using the
iat
andexp
properties elsewhere. I've now fixed it in my app.An entry in the changelog would've help track it down faster, a major version bump would've avoided introducing this with a regular npm-install (depending on
"jsonwebtoken": "^5.4.1"
).That said, thanks for your work on the module.