Skip to content

Commit e863feb

Browse files
committed
Refactor HMAC signature verification in base.mjs to ensure proper handling of unauthorized requests
1 parent 190ae32 commit e863feb

File tree

1 file changed

+10
-8
lines changed
  • components/picqer/sources/common

1 file changed

+10
-8
lines changed

components/picqer/sources/common/base.mjs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,17 @@ export default {
5555
async run(event) {
5656
const { body } = event;
5757
const signature = event?.headers["x-picqer-signature"];
58-
const hash = CryptoJS.HmacSHA256(event.bodyRaw, this.secret);
59-
const hashBase64 = CryptoJS.enc.Base64.stringify(hash);
58+
if (signature) {
59+
const hash = CryptoJS.HmacSHA256(event.bodyRaw, this.secret);
60+
const hashBase64 = CryptoJS.enc.Base64.stringify(hash);
6061

61-
if (hashBase64 !== signature) {
62-
this.http.respond({
63-
status: 401,
64-
body: "Unauthorized",
65-
});
66-
return;
62+
if (hashBase64 !== signature) {
63+
this.http.respond({
64+
status: 401,
65+
body: "Unauthorized",
66+
});
67+
return;
68+
}
6769
}
6870

6971
this.http.respond({

0 commit comments

Comments
 (0)