From 7e4d0020c8639f70ec9d2f5b78d673cffa52cb80 Mon Sep 17 00:00:00 2001 From: Aaron Croissette Date: Sat, 20 Apr 2024 11:37:45 -0400 Subject: [PATCH 01/12] feat: catch JWK multiple public key match --- src/index.ts | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 0e70509..136f30a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,8 @@ import { jwtVerify, type JWTPayload, type JWSHeaderParameters, - type KeyLike + type KeyLike, + errors, } from 'jose' import { Type as t } from '@sinclair/typebox' @@ -158,7 +159,28 @@ JWTOption) => { if (!jwt) return false try { - const data: any = (await jwtVerify(jwt, key)).payload + const data: any = (await jwtVerify(jwt, key) + .catch(async (error) => { + if (error?.code === 'ERR_JWKS_MULTIPLE_MATCHING_KEYS') { + for await (const publicKey of error) { + try { + return await jwtVerify(jwt, publicKey) + } + catch (innerError) { + if (innerError?.code === 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED') { + continue; + } + + throw innerError + } + } + + throw new errors.JWSSignatureVerificationFailed() + } + + throw error + }) + ).payload if (validator && !validator!.Check(data)) throw new ValidationError('JWT', validator, data) From 849d23477edbc9afeab1e7cd9b2168df501e457e Mon Sep 17 00:00:00 2001 From: Aaron Croissette Date: Sat, 20 Apr 2024 11:39:43 -0400 Subject: [PATCH 02/12] feat: expose JWTVerifyGetKey type for secret parameter --- src/index.ts | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/index.ts b/src/index.ts index 136f30a..7944232 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,6 +7,7 @@ import { type JWSHeaderParameters, type KeyLike, errors, + type JWTVerifyGetKey, } from 'jose' import { Type as t } from '@sinclair/typebox' @@ -31,7 +32,7 @@ export interface JWTOption< Name extends string | undefined = 'jwt', Schema extends TSchema | undefined = undefined > extends JWSHeaderParameters, - Omit { + Omit { /** * Name to decorate method as * @@ -54,7 +55,7 @@ export interface JWTOption< /** * JWT Secret */ - secret: string | Uint8Array | KeyLike + secret: string | Uint8Array | KeyLike | JWTVerifyGetKey /** * Type strict validation for JWT payload */ @@ -91,7 +92,7 @@ export const jwt = < exp, ...payload }: // End JWT Payload -JWTOption) => { + JWTOption) => { if (!secret) throw new Error("Secret can't be empty") const key = @@ -99,22 +100,22 @@ JWTOption) => { const validator = schema ? getSchemaValidator( - t.Intersect([ - schema, - t.Object({ - iss: t.Optional(t.String()), - sub: t.Optional(t.String()), - aud: t.Optional( - t.Union([t.String(), t.Array(t.String())]) - ), - jti: t.Optional(t.String()), - nbf: t.Optional(t.Union([t.String(), t.Number()])), - exp: t.Optional(t.Union([t.String(), t.Number()])), - iat: t.Optional(t.String()) - }) - ]), - {} - ) + t.Intersect([ + schema, + t.Object({ + iss: t.Optional(t.String()), + sub: t.Optional(t.String()), + aud: t.Optional( + t.Union([t.String(), t.Array(t.String())]) + ), + jti: t.Optional(t.String()), + nbf: t.Optional(t.Union([t.String(), t.Number()])), + exp: t.Optional(t.Union([t.String(), t.Number()])), + iat: t.Optional(t.String()) + }) + ]), + {} + ) : undefined return new Elysia({ @@ -153,7 +154,7 @@ JWTOption) => { jwt?: string ): Promise< | (UnwrapSchema> & - JWTPayloadSpec) + JWTPayloadSpec) | false > => { if (!jwt) return false From 6d24d0cec0d9ed8822b8dba72961a61a8e74a93f Mon Sep 17 00:00:00 2001 From: Aaron Croissette Date: Sat, 20 Apr 2024 13:01:55 -0400 Subject: [PATCH 03/12] fix: jwk types correction --- src/index.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 7944232..ff1c063 100644 --- a/src/index.ts +++ b/src/index.ts @@ -148,6 +148,10 @@ export const jwt = < if (nbf) jwt = jwt.setNotBefore(nbf) if (exp) jwt = jwt.setExpirationTime(exp) + if (!('type' in key) && !(key instanceof Uint8Array)) { + throw new TypeError('Cannot use that secret to sign, likely only verify.'); + } + return jwt.sign(key) }, verify: async ( @@ -160,15 +164,17 @@ export const jwt = < if (!jwt) return false try { - const data: any = (await jwtVerify(jwt, key) + // note: this is to satisfy typescript. + const verification = typeof key === 'function' ? jwtVerify(jwt, key) : jwtVerify(jwt, key); + const data: any = (await verification .catch(async (error) => { if (error?.code === 'ERR_JWKS_MULTIPLE_MATCHING_KEYS') { for await (const publicKey of error) { try { return await jwtVerify(jwt, publicKey) } - catch (innerError) { - if (innerError?.code === 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED') { + catch (innerError: any) { + if ('code' in innerError && innerError?.code === 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED') { continue; } From 5c46859b3fcf28cd3984918c0e8b499ec75f18f3 Mon Sep 17 00:00:00 2001 From: Aaron Croissette Date: Sat, 20 Apr 2024 13:02:29 -0400 Subject: [PATCH 04/12] feat: build on install if no dist is found (e.g. building from source) --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index d4e53f1..e7d0acc 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "scripts": { "dev": "bun run --hot example/index.ts", "test": "bun test && npm run test:node", + "install": "[ -d dist ] || npm run build", "test:node": "npm install --prefix ./test/node/cjs/ && npm install --prefix ./test/node/esm/ && node ./test/node/cjs/index.js && node ./test/node/esm/index.js", "build": "rimraf dist && tsc --project tsconfig.esm.json && tsc --project tsconfig.cjs.json", "release": "npm run build && npm run test && npm publish --access public" From c0fec89459d70debae09f8cedd60dd7d792632cb Mon Sep 17 00:00:00 2001 From: Aaron Croissette Date: Sat, 20 Apr 2024 13:12:29 -0400 Subject: [PATCH 05/12] fix: update postinstall script --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index e7d0acc..a07bc09 100644 --- a/package.json +++ b/package.json @@ -28,11 +28,12 @@ "auth", "authentication" ], + "packageManager": "pnpm@8.6.0", "license": "MIT", "scripts": { "dev": "bun run --hot example/index.ts", "test": "bun test && npm run test:node", - "install": "[ -d dist ] || npm run build", + "postinstall": "if [ ! -d dist ] ; then npm install --dev --ignore-scripts && npm run build; fi;", "test:node": "npm install --prefix ./test/node/cjs/ && npm install --prefix ./test/node/esm/ && node ./test/node/cjs/index.js && node ./test/node/esm/index.js", "build": "rimraf dist && tsc --project tsconfig.esm.json && tsc --project tsconfig.cjs.json", "release": "npm run build && npm run test && npm publish --access public" From 80cf0efc29e4e1523d66d269e13d89155be34e98 Mon Sep 17 00:00:00 2001 From: Aaron Croissette Date: Sat, 20 Apr 2024 13:33:25 -0400 Subject: [PATCH 06/12] fix: general type export(?) --- src/index.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index ff1c063..48474f1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -97,7 +97,8 @@ export const jwt = < const key = typeof secret === 'string' ? new TextEncoder().encode(secret) : secret - + // note: this is to satisfy typescript. + const verifier = typeof key === 'function' ? (jwt: string) => jwtVerify(jwt, key) : (jwt: string) => jwtVerify(jwt, key); const validator = schema ? getSchemaValidator( t.Intersect([ @@ -164,9 +165,7 @@ export const jwt = < if (!jwt) return false try { - // note: this is to satisfy typescript. - const verification = typeof key === 'function' ? jwtVerify(jwt, key) : jwtVerify(jwt, key); - const data: any = (await verification + const data: any = (await verifier(jwt) .catch(async (error) => { if (error?.code === 'ERR_JWKS_MULTIPLE_MATCHING_KEYS') { for await (const publicKey of error) { From 8cf23cc5135ab7cbf87210428ccf28c9723691da Mon Sep 17 00:00:00 2001 From: Aaron Croissette Date: Sat, 20 Apr 2024 13:46:26 -0400 Subject: [PATCH 07/12] docs: update comment location --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 48474f1..79d0e2f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -97,7 +97,6 @@ export const jwt = < const key = typeof secret === 'string' ? new TextEncoder().encode(secret) : secret - // note: this is to satisfy typescript. const verifier = typeof key === 'function' ? (jwt: string) => jwtVerify(jwt, key) : (jwt: string) => jwtVerify(jwt, key); const validator = schema ? getSchemaValidator( @@ -165,6 +164,7 @@ export const jwt = < if (!jwt) return false try { + // note: this is to satisfy typescript. const data: any = (await verifier(jwt) .catch(async (error) => { if (error?.code === 'ERR_JWKS_MULTIPLE_MATCHING_KEYS') { From e84f943da8fda72992a892f77a25fbca2e01f41c Mon Sep 17 00:00:00 2001 From: Aaron Croissette Date: Sat, 20 Apr 2024 14:19:29 -0400 Subject: [PATCH 08/12] feat: pass through options on verify call, refactor types --- src/index.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index 79d0e2f..4e6bbea 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,6 +8,8 @@ import { type KeyLike, errors, type JWTVerifyGetKey, + type JWTVerifyOptions, + type JWTVerifyResult, } from 'jose' import { Type as t } from '@sinclair/typebox' @@ -97,7 +99,11 @@ export const jwt = < const key = typeof secret === 'string' ? new TextEncoder().encode(secret) : secret - const verifier = typeof key === 'function' ? (jwt: string) => jwtVerify(jwt, key) : (jwt: string) => jwtVerify(jwt, key); + const verifier: { + (jwt: string, options?: JWTVerifyOptions): Promise + } = typeof key === 'function' + ? (jwt, options) => jwtVerify(jwt, key, options) + : (jwt, options) => jwtVerify(jwt, key, options); const validator = schema ? getSchemaValidator( t.Intersect([ @@ -135,6 +141,10 @@ export const jwt = < morePayload: UnwrapSchema> & JWTPayloadSpec ) => { + if (typeof key === 'function') { + throw new TypeError('Cannot use that secret to sign, likely only verify.'); + } + let jwt = new SignJWT({ ...payload, ...morePayload, @@ -148,14 +158,11 @@ export const jwt = < if (nbf) jwt = jwt.setNotBefore(nbf) if (exp) jwt = jwt.setExpirationTime(exp) - if (!('type' in key) && !(key instanceof Uint8Array)) { - throw new TypeError('Cannot use that secret to sign, likely only verify.'); - } - return jwt.sign(key) }, verify: async ( - jwt?: string + jwt?: string, + options?: JWTVerifyOptions, ): Promise< | (UnwrapSchema> & JWTPayloadSpec) @@ -165,12 +172,12 @@ export const jwt = < try { // note: this is to satisfy typescript. - const data: any = (await verifier(jwt) + const data: any = (await verifier(jwt, options) .catch(async (error) => { if (error?.code === 'ERR_JWKS_MULTIPLE_MATCHING_KEYS') { for await (const publicKey of error) { try { - return await jwtVerify(jwt, publicKey) + return await jwtVerify(jwt, publicKey, options) } catch (innerError: any) { if ('code' in innerError && innerError?.code === 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED') { From 0f1465922b71f22614fba8698a2e390cba627f12 Mon Sep 17 00:00:00 2001 From: Aaron Croissette Date: Sat, 20 Apr 2024 14:27:58 -0400 Subject: [PATCH 09/12] fix: move things around to try and satisfy typiness --- src/index.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index 4e6bbea..773c46b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -78,6 +78,15 @@ export interface JWTOption< exp?: string | number } +const verifier = (key: Uint8Array | KeyLike | JWTVerifyGetKey): { + (jwt: string, options?: JWTVerifyOptions): Promise +} => { + return typeof key === 'function' + ? (jwt, options) => jwtVerify(jwt, key, options) + : (jwt, options) => jwtVerify(jwt, key, options) + ; +} + export const jwt = < const Name extends string = 'jwt', const Schema extends TSchema | undefined = undefined @@ -99,11 +108,7 @@ export const jwt = < const key = typeof secret === 'string' ? new TextEncoder().encode(secret) : secret - const verifier: { - (jwt: string, options?: JWTVerifyOptions): Promise - } = typeof key === 'function' - ? (jwt, options) => jwtVerify(jwt, key, options) - : (jwt, options) => jwtVerify(jwt, key, options); + const verifyKey = verifier(key); const validator = schema ? getSchemaValidator( t.Intersect([ @@ -172,7 +177,7 @@ export const jwt = < try { // note: this is to satisfy typescript. - const data: any = (await verifier(jwt, options) + const data: any = (await verifyKey(jwt, options) .catch(async (error) => { if (error?.code === 'ERR_JWKS_MULTIPLE_MATCHING_KEYS') { for await (const publicKey of error) { From 63c37e1185538ede920765e91b74882db6fa24dd Mon Sep 17 00:00:00 2001 From: Aaron Croissette Date: Sat, 20 Apr 2024 14:53:37 -0400 Subject: [PATCH 10/12] feat: distilled --- src/index.ts | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/index.ts b/src/index.ts index 773c46b..8bbc719 100644 --- a/src/index.ts +++ b/src/index.ts @@ -84,7 +84,7 @@ const verifier = (key: Uint8Array | KeyLike | JWTVerifyGetKey): { return typeof key === 'function' ? (jwt, options) => jwtVerify(jwt, key, options) : (jwt, options) => jwtVerify(jwt, key, options) - ; + ; } export const jwt = < @@ -177,27 +177,28 @@ export const jwt = < try { // note: this is to satisfy typescript. - const data: any = (await verifyKey(jwt, options) - .catch(async (error) => { - if (error?.code === 'ERR_JWKS_MULTIPLE_MATCHING_KEYS') { - for await (const publicKey of error) { - try { - return await jwtVerify(jwt, publicKey, options) - } - catch (innerError: any) { - if ('code' in innerError && innerError?.code === 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED') { - continue; + const data: any = ( + await (verifyKey(jwt, options) + .catch(async (error) => { + if (error?.code === 'ERR_JWKS_MULTIPLE_MATCHING_KEYS') { + for await (const publicKey of error) { + try { + return await jwtVerify(jwt, publicKey, options) } + catch (innerError: any) { + if ('code' in innerError && innerError?.code === 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED') { + continue; + } - throw innerError + throw innerError + } } - } - throw new errors.JWSSignatureVerificationFailed() - } + throw new errors.JWSSignatureVerificationFailed() + } - throw error - }) + throw error + })) ).payload if (validator && !validator!.Check(data)) From bf9bad8667caa5daf25b3bd613b3d66f5a54363c Mon Sep 17 00:00:00 2001 From: Aaron Croissette Date: Sat, 20 Apr 2024 15:01:01 -0400 Subject: [PATCH 11/12] refactor: modify inline app --- bun.lockb | Bin 60265 -> 59847 bytes package.json | 4 ++-- src/index.ts | 30 ++++++++++++++++-------------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/bun.lockb b/bun.lockb index c875dfc2a831ef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Rdg=@FwvRs_sSV9_xERy(6G^K&oL1w-7unJue0IQf zr=}W#XDp5SI-EA+A@}p?=cjn$d(NU?_z7=5ji$8DNm4L|YC0{bnddv7(QAh8+n0}s zmF{!mVYhByh1Gc2RgD^2*0Hf{s>D&5LIvANaa~TE@o?L`ar_&XkIc3}M*)f#8#wYc zw`;WAm8jQO32o?7_)h9HzVva|6saSL9Q!Bn<@E3S6|3WCjuq}P(kcEBRtvr^%KJcPw}V5=0gQFyli zs48pd<<>N{>)mCaf1ngVj}sQdg6F8JTd^7sxzFyEU7a^DB46`J%Rm~nb}OQ$Pjru# z#Uo5S5U0|Y-A?{EbskfA6^%Qn@YQq;?M+mR_99w~ug+gXrw%I89y_fMSZv0tZEwoe zxBlzkzkDn4LPwq!w@>U88+b4>3>^i)rt6xtk?(OLBWlD_My_^D3 zjhNvAaYT{sj-;_iELP(M`qI)9S-$tob(#w>m9f7~h;-Uc?MEIQZcOoy^P`zZBLc}< z&@+D=VLW8z>alO$n!e?@#2X77d4<^W+i2ZUrQq+61oVp|A=lwFp1N)4H#cm5;yoXF ziW~)w+#HrcS;rNt@wC0|KD|Ao@#tsp02MDPwwmIOIZ<#W_=-XtLN6S%{gYzU=G3JB zN!douK8ZNvxA`Ov+VK)&wElQb@@{aV5&UP13NG*`W50hZB=zns3LbX`%1?|-<#~Z! aAO0$a?)F*f*B>UCa~$;*Pf>U6=KlkuhF!V< diff --git a/package.json b/package.json index a07bc09..c3b3b56 100644 --- a/package.json +++ b/package.json @@ -47,12 +47,12 @@ "@types/node": "^20.1.4", "@typescript-eslint/eslint-plugin": "^6.6.0", "@typescript-eslint/parser": "^6.6.0", - "elysia": "1.0.2", + "elysia": "1.0.13", "eslint": "^8.40.0", "rimraf": "4.3", "typescript": "^5.1.6" }, "peerDependencies": { - "elysia": ">= 1.0.2" + "elysia": ">= 1.0.13" } } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 8bbc719..768476e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -103,7 +103,8 @@ export const jwt = < exp, ...payload }: // End JWT Payload - JWTOption) => { + JWTOption +) => (app: Elysia) => { if (!secret) throw new Error("Secret can't be empty") const key = @@ -129,19 +130,20 @@ export const jwt = < ) : undefined - return new Elysia({ - name: '@elysiajs/jwt', - seed: { - name, - secret, - alg, - crit, - schema, - nbf, - exp, - ...payload - } - }).decorate(name as Name extends string ? Name : 'jwt', { + // return new Elysia({ + // name: '@elysiajs/jwt', + // seed: { + // name, + // secret, + // alg, + // crit, + // schema, + // nbf, + // exp, + // ...payload + // } + // }) + return app.decorate(name as Name extends string ? Name : 'jwt', { sign: ( morePayload: UnwrapSchema> & JWTPayloadSpec From d3957f89e3df6eb4cf69d7a3f530bdcb70ff1dcc Mon Sep 17 00:00:00 2001 From: Aaron Croissette Date: Sat, 20 Apr 2024 15:21:54 -0400 Subject: [PATCH 12/12] fix: allow bun to install or npm --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c3b3b56..03cea79 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "scripts": { "dev": "bun run --hot example/index.ts", "test": "bun test && npm run test:node", - "postinstall": "if [ ! -d dist ] ; then npm install --dev --ignore-scripts && npm run build; fi;", + "postinstall": "if [ ! -d dist ] ; then bun install --dev --ignore-scripts || npm install --dev --ignore-scripts; npm run build; fi;", "test:node": "npm install --prefix ./test/node/cjs/ && npm install --prefix ./test/node/esm/ && node ./test/node/cjs/index.js && node ./test/node/esm/index.js", "build": "rimraf dist && tsc --project tsconfig.esm.json && tsc --project tsconfig.cjs.json", "release": "npm run build && npm run test && npm publish --access public"