diff --git a/test/claim-aud.test.js b/test/claim-aud.test.js index 3a27fd89..c125f10d 100644 --- a/test/claim-aud.test.js +++ b/test/claim-aud.test.js @@ -431,6 +431,15 @@ describe('audience', function() { }); }); }); + + it('should error with a Regex verify "audience" option that matches any string', function (done) { + verifyWithAudience(token, /.+/, (err) => { + testUtils.asyncCheck(done, () => { + expect(err).to.be.instanceOf(jwt.JsonWebTokenError); + expect(err).to.have.property('message', 'jwt audience invalid. expected: /.+/'); + }); + }); + }); }); }); }); diff --git a/verify.js b/verify.js index cdbfdc45..59381108 100644 --- a/verify.js +++ b/verify.js @@ -197,7 +197,7 @@ module.exports = function (jwtString, secretOrPublicKey, options, callback) { const match = target.some(function (targetAudience) { return audiences.some(function (audience) { - return audience instanceof RegExp ? audience.test(targetAudience) : audience === targetAudience; + return audience instanceof RegExp ? typeof targetAudience === 'string' && audience.test(targetAudience) : audience === targetAudience; }); });