Skip to content

Commit 0d228f2

Browse files
fix: detect JWTInvalidError from DOMException in jose 6.2.6+
1 parent 07f6db5 commit 0d228f2

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

packages/nodejs-lib/src/jwt/jwt.service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,11 @@ export class JWTService<T extends AnyObject = AnyObject> {
379379
if (err instanceof errors.JOSEError) {
380380
return new JWTInvalidError(err.message, errorData)
381381
}
382-
if (this.cfg.verifyAlgorithms && err instanceof TypeError) {
382+
if (this.cfg.verifyAlgorithms && (err instanceof TypeError || err instanceof DOMException)) {
383383
// With multiple verifyAlgorithms, a token/key algorithm mismatch is reachable
384-
// by untrusted input, and jose reports it as TypeError - treat it as an invalid token
384+
// by untrusted input, and jose reports it as TypeError, or (since jose 6.2.6,
385+
// which prepares keys via Node's KeyObject.toCryptoKey) as DOMException
386+
// "DataError: Invalid key type" - treat it as an invalid token
385387
return new JWTInvalidError(err.message, errorData)
386388
}
387389
return err as Error

0 commit comments

Comments
 (0)