diff --git a/src/errors/index.ts b/src/errors/index.ts new file mode 100644 index 0000000..cc1f5da --- /dev/null +++ b/src/errors/index.ts @@ -0,0 +1 @@ +export { UnsupportedAlgorithmError } from './unsupported-algorithm-error'; diff --git a/src/errors/unsupported-algorithm-error.ts b/src/errors/unsupported-algorithm-error.ts new file mode 100644 index 0000000..b770515 --- /dev/null +++ b/src/errors/unsupported-algorithm-error.ts @@ -0,0 +1,6 @@ +/** + * Thrown when a key is presented to verify a signature with + * an algorithm that is not supported + */ +export class UnsupportedAlgorithmError extends Error { +} diff --git a/src/httpbis/index.ts b/src/httpbis/index.ts index b5664cd..3586b16 100644 --- a/src/httpbis/index.ts +++ b/src/httpbis/index.ts @@ -24,6 +24,7 @@ import { CommonConfig, VerifyingKey, } from '../types'; +import { UnsupportedAlgorithmError } from '../errors'; export function deriveComponent(component: string, params: Map, res: Response, req?: Request): string[]; export function deriveComponent(component: string, params: Map, req: Request): string[]; @@ -378,6 +379,10 @@ export async function verifyMessage(config: VerifyConfig, message: Request | Res return params; }, {})), ]); + if (input[1].has('alg') && key.algs?.includes(input[1].get('alg') as string) === false) { + throw new UnsupportedAlgorithmError('Unsupported key algorithm'); + } + // @todo - confirm this is all working as expected if (!config.all && !key) { return null; }