Merge pull request #17 from saleor/13-handle-missing-payload-signature

Handle missing webhook signature header
This commit is contained in:
Krzysztof Wolski 2022-08-08 11:02:19 +02:00 committed by GitHub
commit 8a1b0e7fa2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,7 +3,7 @@ import * as jose from "jose";
import type { Middleware, Request } from "retes";
import { Response } from "retes/response";
import { SALEOR_AUTHORIZATION_BEARER_HEADER } from "./const";
import { SALEOR_AUTHORIZATION_BEARER_HEADER, SALEOR_SIGNATURE_HEADER } from "./const";
import { getSaleorHeaders } from "./headers";
import { jwksUrl } from "./urls";
@ -72,6 +72,13 @@ export const withWebhookSignatureVerified =
const { domain: saleorDomain, signature: payloadSignature } = getSaleorHeaders(request.headers);
if (!payloadSignature) {
return Response.BadRequest({
success: false,
message: `${ERROR_MESSAGE} Missing ${SALEOR_SIGNATURE_HEADER} header.`,
});
}
if (secretKey !== undefined) {
const calculatedSignature = crypto
.createHmac("sha256", secretKey)