Merge commit from fork
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* feat(utils/jwt): add JwtAlgorithmRequired error type Add a new error type to throw when algorithm is not specified during JWT verification. This is part of the security fix to prevent algorithm confusion attacks. * fix(utils/jwt): require alg parameter in verify function BREAKING CHANGE: The `alg` parameter is now required for JWT verification. This prevents algorithm confusion attacks where an attacker could forge tokens by exploiting the default HS256 fallback with asymmetric keys. - Remove HS256 default fallback in verify() function - Make algOrOptions parameter required - Add early validation for undefined algOrOptions - Add validation for undefined alg in options object * fix(middleware/jwt): require alg option in jwt middleware BREAKING CHANGE: The `alg` option is now required when using the JWT middleware. This prevents algorithm confusion attacks. - Make alg property required in options type - Add runtime validation to throw error if alg is not provided - Update JSDoc to reflect required alg parameter - Update example in documentation to include alg option * test(jwt): update tests to use required alg parameter Update existing tests to explicitly specify the alg parameter as it is now required. This is a necessary change due to the security fix that removes the default HS256 fallback. * test(jwt): add security tests for algorithm confusion prevention Add tests to verify the security fix prevents algorithm confusion attacks: - Test that verify() throws JwtAlgorithmRequired when alg is missing - Test that verify() throws when alg is undefined in options - Test that RS256 tokens cannot be verified with HS256 (attack scenario) - Test that middleware throws when alg option is not provided - Test that tokens with mismatched algorithms are rejected * fix(jwt): add algorithm mismatch check between header.alg and options.alg Add JwtAlgorithmMismatch error type and verify that the algorithm specified in the JWT header matches the algorithm provided in options. This prevents algorithm substitution attacks where an attacker might try to use a different algorithm than expected. - Add JwtAlgorithmMismatch error class in types.ts - Check header.alg === options.alg in verify() function - Update HS512/HS384 tests to use correct algorithm in verify - Add explicit test for algorithm mismatch detection - Update existing attack prevention test to expect JwtAlgorithmMismatch
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+221 added−19 removed
- tests:+183 added−13 removed
- other:+38 added−6 removed