30 Commits
Author SHA1 Message Date
Jake LaceyandGitHub 74bd352a25 refactor: use specific lodash packages (#933)
This is to reduce the size of the bundle users have to install.
2023-08-30 13:06:25 +01:00
925d95de54 Merge pull request from GHSA-8cf7-32gw-wr33
* Check if node version supports asymmetricKeyDetails

* Validate algorithms for ec key type

* Rename variable

* Rename function

* Add early return for symmetric keys

* Validate algorithm for RSA key type

* Validate algorithm for RSA-PSS key type

* Check key types for EdDSA algorithm

* Rename function

* Move validateKey function to module

* Convert arrow to function notation

* Validate key in verify function

* Simplify if

* Convert if to switch..case

* Guard against empty key in validation

* Remove empty line

* Add lib to check modulus length

* Add modulus length checks

* Validate mgf1HashAlgorithm and saltLength

* Check node version before using key details API

* Use built-in modulus length getter

* Fix Node version validations

* Remove duplicate validateKey

* Add periods to error messages

* Fix validation in verify function

* Make asymmetric key validation the latest validation step

* Change key curve validation

* Remove support for ES256K

* Fix old test that was using wrong key types to sign tokens

* Enable RSA-PSS for old Node versions

* Add specific RSA-PSS validations on Node 16 LTS+

* Improve error message

* Simplify key validation code

* Fix typo

* Improve error message

* Change var to const in test

* Change const to let to avoid reassigning problem

* Improve error message

* Test incorrect private key type

* Rename invalid to unsupported

* Test verifying of jwt token with unsupported key

* Test invalid private key type

* Change order of object parameters

* Move validation test to separate file

* Move all validation tests to separate file

* Add prime256v1 ec key

* Remove modulus length check

* WIP: Add EC key validation tests

* Fix node version checks

* Fix error message check on test

* Add successful tests for EC curve check

* Remove only from describe

* Remove `only`

* Remove duplicate block of code

* Move variable to a different scope and make it const

* Convert allowed curves to object for faster lookup

* Rename variable

* Change variable assignment order

* Remove unused object properties

* Test RSA-PSS happy path and wrong length

* Add missing tests

* Pass validation if no algorithm has been provided

* Test validation of invalid salt length

* Test error when signing token with invalid key

* Change var to const/let in verify tests

* Test verifying token with invalid key

* Improve test error messages

* Add parameter to skip private key validation

* Replace DSA key with a 4096 bit long key

* Test allowInvalidPrivateKeys in key signing

* Improve test message

* Rename variable

* Add key validation flag tests

* Fix variable name in Readme

* Change private to public dsa key in verify

* Rename flag

* Run EC validation tests conditionally

* Fix tests in old node versions

* Ignore block of code from test coverage

* Separate EC validations tests into two different ones

* Add comment

* Wrap switch in if instead of having an early return

* Remove unsupported algorithms from asymmetric key validation

* Rename option to allowInvalidAsymmetricKeyTypes and improve Readme

* 9.0.0

* adding migration notes to readme

* adding changelog for version 9.0.0

Co-authored-by: julienwoll <[email protected]>
2022-12-21 13:36:01 +01:00
david-renaud-oktaandGitHub 44ce6fd923 fix!: Prevent accidental use of insecure key sizes & misconfiguration of secrets (#852)
* fix!: Disable use of weak RSA key sizes for asymmetric algorithms

Added checks to prevent invalid secrets from being used with the HS*** algorithms when signing and verifying
Added checks to prevent the use of insecure asymmetric key sizes except when explicitly overriden via options
Prevented Buffers containing malicious objects from being used as key material.

BREAKING CHANGE: Requires node 12.x or later to allow use of `KeyObject`
2022-11-29 11:58:59 -05:00
Pedro Luiz Cabral Salomon PradoandFilip Skokan f245a7ee9d style: add missing semicolon (#641) 2019-10-21 13:23:57 +02:00
Filip SkokanandEduardo Diaz 11a0453c51 feat: add PS JWA support for applicable node versions (#573) 2019-02-20 13:42:37 +01:00
Lio李欧andEduardo Diaz f1f30a38a3 Force use_strict during testing (#577)
* Force use_strict during testing

* Add string payload test cases to .iat tests
2019-02-20 13:22:27 +01:00
Andrew NesterandEduardo Diaz e1af5cfd31 Fixed error message when empty string passed as expiresIn or notBefore option (#531)
* Fixed error message when empty string passed as expiresIn or notBefore option

* Moved tests to option validation block
2018-10-22 20:40:25 +02:00
Tim OramandEduardo Diaz bb40b2103d Implement async/sync tests for nbf claim (#537)
Refactor the existing tests for the nbf claim to use the async/sync test
helpers. This required fixing a case where an error was improperly
handled for an async call.
2018-10-16 19:46:21 +02:00
Tim OramandEduardo Diaz da8a850628 Implement async/sync tests for exp claim (#536)
Refactor existing tests for the exp claim to use the async/sync test
helpers. This required fixing a case where an error was improperly
handled in the async case.
2018-10-16 18:57:20 +02:00
Jaco KosterandEduardo Diaz 4d2a22c975 Secret callback revisited (#480)
* Introduction of the secret callback

Without the more contentious 'none'-changes

* Removed some spaces...

I should really add a editor.config and eslint to this project ;-)

* Removed xtend as a dependency, as the native Object.Assign can do this as well

* Removed xtend as a dependency, as the native Object.Assign can do this as well

* Resolve feedback from review

* Added extra test and fixed the associated bug

* The return of the header

* Forgot to change this one as well... Sorry bout that

* Updated the readme and made the if-statements consistent

* Space; The final frontier
2018-06-11 17:32:29 +02:00
Jonathan Gros-DuboisandEduardo Diaz cab1c43ee4 Add a new mutatePayload option (#446)
This option allows you to keep a reference to the raw token payload after claims have been applied to it but before it has been encoded.
2018-03-02 13:48:25 +01:00
Tim OramandEduardo Diaz 9f9d93b40e Not Before (nbf) calculated based on iat/timestamp (#437)
fix #435
2018-01-19 18:28:49 +01:00
Jeff AlderandEduardo Diaz b848551927 #403: Clarify error wording. (#409)
* #403: Clarify error wording.

* #403: Improve wording for payload vs options
2017-10-09 19:29:48 +02:00
Tomas ChmelevskijandEduardo Diaz 8fe1f3f44f Remove lodash.isarray dependency (#394) 2017-09-12 12:52:22 +02:00
Chris PriceandEduardo Diaz 75b897b11d Remove joi to shrink module size (#348)
* Add cost-of-modules report to npm test

Results before any changes

┌─────────────┬────────────┬───────┐
│ name        │ children   │ size  │
├─────────────┼────────────┼───────┤
│ joi         │ 4          │ 3.12M │ <--!!!
├─────────────┼────────────┼───────┤
│ jws         │ 5          │ 0.18M │
├─────────────┼────────────┼───────┤
│ lodash.once │ 0          │ 0.01M │
├─────────────┼────────────┼───────┤
│ ms          │ 0          │ 0.01M │
├─────────────┼────────────┼───────┤
│ xtend       │ 0          │ 0.00M │
├─────────────┼────────────┼───────┤
│ 5 modules   │ 9 children │ 3.32M │
└─────────────┴────────────┴───────┘

* Replace joi with bespoke validator based on lodash

Dramatically reduces the module size without breaking ES5 compatability -

┌──────────────────────┬────────────┬───────┐
│ name                 │ children   │ size  │
├──────────────────────┼────────────┼───────┤
│ jws                  │ 5          │ 0.18M │
├──────────────────────┼────────────┼───────┤
│ lodash.includes      │ 0          │ 0.02M │
├──────────────────────┼────────────┼───────┤
│ lodash.once          │ 0          │ 0.01M │
├──────────────────────┼────────────┼───────┤
│ lodash.isinteger     │ 0          │ 0.01M │
├──────────────────────┼────────────┼───────┤
│ ms                   │ 0          │ 0.01M │
├──────────────────────┼────────────┼───────┤
│ lodash.isplainobject │ 0          │ 0.01M │
├──────────────────────┼────────────┼───────┤
│ xtend                │ 0          │ 0.00M │
├──────────────────────┼────────────┼───────┤
│ lodash.isstring      │ 0          │ 0.00M │
├──────────────────────┼────────────┼───────┤
│ lodash.isboolean     │ 0          │ 0.00M │
├──────────────────────┼────────────┼───────┤
│ lodash.isnumber      │ 0          │ 0.00M │
├──────────────────────┼────────────┼───────┤
│ lodash.isarray       │ 0          │ 0.00M │
├──────────────────────┼────────────┼───────┤
│ 11 modules           │ 5 children │ 0.25M │
└──────────────────────┴────────────┴───────┘

* Enhance validator error messages and add tests
2017-09-06 16:24:55 +02:00
Eduardo Diaz d63c87dc7c add test & modify guard code 2017-08-17 13:50:26 +02:00
Rhys Anthony McCaig 95e73a269a Fix for #381. Set secret string before using jws when alg is none 2017-08-11 17:25:55 -07:00
Eduardo Diaz 4cc2615033 sign: add check to be sure secret has a value 2017-07-24 16:59:07 -05:00
Eduardo Diaz 87d9e777ed Make Options object optional for callback-ish sign 2017-03-08 14:09:04 +01:00
Ryan Parman 2f220de780 Simpler PR which implements the changes from #249. 2016-11-28 11:50:37 -08:00
Christian Holm 3ac95ad93e Use lodash.once instead of unlicensed/unmaintained cb 2016-07-21 08:48:32 +02:00
José F. Romaniello 6b50ff324b fix issue with buffer payload. closes #216 2016-07-15 09:32:35 -03:00
José F. Romaniello 758ca5eeca temporarly fix an issue of double callback in JWS 2016-07-14 17:30:25 -03:00
José F. Romaniello 084f537d3d do not stringify the payload when signing async - closes #224 2016-07-12 10:06:23 -03:00
lusarz 757a16e0e3 Exp calculated based on iat. fix #217 2016-06-22 10:42:23 +02:00
José F. Romaniello 1e46c5a42a change jwt.sign to return errors on callback instead of throwing errors 2016-05-19 12:47:24 -03:00
José F. Romaniello 65ddea934f Merge branch 'origin/clock_skew_tolerance' of https://github.com/jacopofar/node-jsonwebtoken into jacopofar-origin/clock_skew_tolerance 2016-04-29 11:30:21 -03:00
José F. Romaniello b51e31f477 include standard claims from payload. closes #196 2016-04-28 19:55:05 -03:00
José F. Romaniello 304f1b3307 throw error on invalid options when the payload is not an object 2016-04-27 12:49:54 -03:00
José F. Romaniello 53c3987b3c Improved the sign method
Notable changes:

1.  `expiresInMinutes` and `expiresInSeconds` are deprecated and no longer supported.
2.  `notBeforeInMinutes` and `notBeforeInSeconds` are deprecated and no longer supported.
3.  options are properly validated.
4.  `options.expiresIn`, `options.notBefore`, `options.audience`, `options.issuer`, `options.subject` and `options.jwtid` are mutually exclusive with `payload.exp`, `payload.nbf`, `payload.aud`, `payload.iss`, `payload.sub` and `payload.jti` respectively.
5.  `options.algorithm` is properly validated.
6.  `options.headers` is renamed to `options.header`.
2016-04-27 12:40:28 -03:00