20 Commits
Author SHA1 Message Date
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
Jake LaceyandGitHub 59d32eeef4 fix(sign&verify)!: Remove default none support from sign and verify methods, and require it to be explicitly configured (#851)
* fix(sign&verify)!: Remove default none support from sign and verify methods, and require it to be explicitly configured

BREAKING CHANGE: Removes fallback for none algorithm for the verify method.
2022-11-29 14:32:41 +00:00
dviryaminandGitHub 2687f0cdd4 Replace tilde-indexOf with includes (#647)
* Replace tilde-indexOf with includes

* remove package lock
2020-02-10 16:55:58 +01:00
Filip SkokanandEduardo Diaz 11a0453c51 feat: add PS JWA support for applicable node versions (#573) 2019-02-20 13:42:37 +01:00
Javier EspinosaandEduardo Diaz 1e880c8c19 Add complete option in jwt.verify (#522)
* Add complete option in verify

* Remove comment

* Update README.md

Co-Authored-By: javespi <[email protected]>

* Move tests in a specific file
2019-02-20 13:32:23 +01:00
kazuki229andEduardo Diaz c7e16cb5d5 Add verify option for nonce validation (#540)
* Add verify option for nonce validation

* Update README.md

Co-Authored-By: kazuki229 <[email protected]>

* Refactor option-nonce test

* Add nonce option validation
2018-11-14 11:02:59 +01: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
TheBusCantSwimandEduardo Diaz 5193ee5616 Enhance audience check to verify against regular expressions (#398)
* Enhance audience check to verify against regular expressions

* Enhance audience check to verify against regular expressions

* Adapted README to have a showcase of the new RegExp-check for the audience validation
2017-10-09 19:29:15 +02:00
Fredrik LiljegrenandGitHub 3f2bff62d4 Merge pull request #349 from ziluvatar/fix-max-age-number-and-seconds
maxAge: Fix logic with number + use seconds instead of ms
2017-09-06 16:43:23 +02:00
ilyapxandEduardo Diaz 2bbd6a37b4 verify: remove process.nextTick (#302)
running synchronous code asynchronously using process.nextTick
has a negative latency impact
2017-09-06 16:41:55 +02:00
Eduardo Diaz 23cb6f1d24 maxAge: Add validation to timespan result 2017-08-29 12:24:08 +02:00
Eduardo Diaz 543bf7f71d maxAge: Fix logic with number + use seconds instead of ms 2017-05-13 17:29:19 +02:00
Michael BorstandEduardo Diaz 912e40685f Allow user to specify now. (#274) 2017-02-10 19:27:44 +01:00
Sergey MaslyakovandEduardo Diaz 047f1ae04b Raise jws.decode error to avoid confusion with "invalid token" error (#294)
* Corrected indistinguishable error messages

jws.decode() never throws an error. At least, in its current version. However, if it were to throw an exception, the diagnostics would be indistinguishable from a soft failure to decode a token. I had an extra trailing space on my JWT and it took me some additional debugging work to trace the actual root cause because the error message was not distinct.

* Allowed an exception from inside of jws.decode to be handled by the caller. Currently, jws.decode never throws an exception. The change is made per discsussion in the original PR

* Added a test case and proper forwarding of the possible exception thrown from jws.decode

* Typo correction
2017-02-09 13:54:58 +01:00
Ricardo GamaandEduardo Diaz c4f7670972 Fix handling non string tokens (#305) 2017-02-03 21:07:54 +01:00
José F. Romaniello d06359ef3b Revert "Merge branch 'venatir-master'"
This reverts commit d66d4ebd3e, reversing
changes made to 5117aacd01.
2016-08-11 13:22:15 -03:00
Mircea Danila Dumitrescu 55d5834f7b Removing unnecessary extra decoding. jwtString is already verified as valid and signature checked 2016-08-10 09:52:10 +01:00
José F. Romaniello 63263a28a2 do not mutate options in jwt.verify, closes #227 2016-07-12 09:52:32 -03:00
José F. Romaniello e11d505207 refactor into multiple files 2016-07-12 09:49:04 -03:00