# Asana API Webhooks - verifying X-Hook-Signature in Node & TS

**URL:** <https://forum.asana.com/t/asana-api-webhooks-verifying-x-hook-signature-in-node-ts/163484>\
**Category:** API & Developers\
**Tags:** webhooks, authentication, api\
**Created:** [3 May 2022 09:31 UTC](https://forum.asana.com/t/asana-api-webhooks-verifying-x-hook-signature-in-node-ts/163484 "2022-05-03T09:31:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon55203160](https://luna1.co/8d76cd.png) [@anon55203160](https://forum.asana.com/u/anon55203160)\
**Post date:** [3 May 2022 09:31 UTC](https://forum.asana.com/t/asana-api-webhooks-verifying-x-hook-signature-in-node-ts/163484/1 "2022-05-03T09:31:44Z")

</div>

I would like to verify incoming requests from Asana on my server. According to the docs the X-Hook-Signature header is computed over the request body using SHA256 HMAC.

If I try to create the signature using the node built-in crypto library, the resulting hashes don’t match up with the header.

The documentation sadly didn’t specify how exactly the body has to be passed to the function. I tried passing it as string, JSON.stringyfied, Buffer etc. Nothing seems to generate matching signatures.

Currently the sever uses express.json() as middleware, but I also tried using express.raw() & express.text(). I also tried setting up my own middleware that added a req.rawBody property to hold the request body as buffer.

Would be nice if someone could help me out. 🙂

Minimal exmaple in TS:

 ![carbon (1)](https://us1.discourse-cdn.com/asana/original/3X/8/e/8eec2c59b9ef7ec8b72d9909d194d3e2459f55a2.png)

---

<div class="post-metadata">

**Author:** ![Simon16](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/simon16/32/107618_2.png) [@Simon16](https://forum.asana.com/u/Simon16)\
**Post date:** [26 July 2022 09:41 UTC](https://forum.asana.com/t/asana-api-webhooks-verifying-x-hook-signature-in-node-ts/163484/2 "2022-07-26T09:41:04Z")

</div>

Hello,

I have the same exact problem.  
I follow the guideline available here [Webhooks](https://developers.asana.com/docs/setting-up-a-webhook)  
The source code used in the video is available here [https://github.com/Asana/devrel-examples/blob/master/javascript/webhooks-nodejs/index.js](https://github.com/Asana/devrel-examples/blob/master/javascript/webhooks-nodejs/index.js)

I followed the security protocole presented in the video.  
I correctly get and save the secret present in the x-hook-secret header during the webhook creation.

My webhook seems to work correctly as my server receive the webhook events.

However during the security check the value of the **computedSignature** and **headers[“x-hook-signature”]** are not the same, so the check fail…

Here is an extract of the source code

```auto
if (req.headers["x-hook-signature"]) {
    const computedSignature = crypto
      .createHmac("SHA256", secret)
      .update(JSON.stringify(req.body))
      .digest("hex");
    if (
      !crypto.timingSafeEqual(
        Buffer.from(req.headers["x-hook-signature"]),
        Buffer.from(computedSignature)
      )
    ) {
      // Fail
      res.sendStatus(401);
    } else {
      // Success
      res.sendStatus(200);
      console.log(`Events on ${Date()}:`);
      console.log(req.body.events);
    }
  }

```

---

<div class="post-metadata">

**Author:** ![Phil\_Seeman](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/phil_seeman/32/81525_2.png) [@Phil\_Seeman](https://forum.asana.com/u/Phil_Seeman)\
**Post date:** [28 July 2022 02:54 UTC](https://forum.asana.com/t/asana-api-webhooks-verifying-x-hook-signature-in-node-ts/163484/4 "2022-07-28T02:54:11Z")

</div>

> [@Simon16](#):
>
> `.update(JSON.stringify(req.body))`

Instead of `req.body`, use `req.body.data`

---

<div class="post-metadata">

**Author:** ![Simon16](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/simon16/32/107618_2.png) [@Simon16](https://forum.asana.com/u/Simon16)\
**Post date:** [28 July 2022 05:25 UTC](https://forum.asana.com/t/asana-api-webhooks-verifying-x-hook-signature-in-node-ts/163484/5 "2022-07-28T05:25:53Z")

</div>

Hi Phil,

Thanks for taking the time to answer.  
Actually my body look like this:

```auto
body = {
    "events": [
        {
            "user": {
                "gid": "123456789",
                "resource_type": "user"
            },
            "created_at": "2022-07-27T14:19:19.062Z",
            "action": "added",
            "resource": {
                "gid": "123456789",
                "resource_type": "story",
                "resource_subtype": "section_changed"
            },
            "parent": {
                "gid": "123456789",
                "resource_type": "task",
                "resource_subtype": "default_task"
            }
        }
    ]
}

```

So there is no “data” field inside.  
Note That I am using an AWS Lambda function instead of a regular webserver  
Thanks,

---

<div class="post-metadata">

**Author:** ![Phil\_Seeman](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/phil_seeman/32/81525_2.png) [@Phil\_Seeman](https://forum.asana.com/u/Phil_Seeman)\
**Post date:** [29 July 2022 04:24 UTC](https://forum.asana.com/t/asana-api-webhooks-verifying-x-hook-signature-in-node-ts/163484/6 "2022-07-29T04:24:18Z")

</div>

> [@Simon16](#):
>
> So there is no “data” field inside.

Ah, right. And your code does match the Github sample you linked to… I’m afraid I don’t have any other ideas as to why it’s not working.

---

<div class="post-metadata">

**Author:** ![Simon16](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/simon16/32/107618_2.png) [@Simon16](https://forum.asana.com/u/Simon16)\
**Post date:** [8 August 2022 05:44 UTC](https://forum.asana.com/t/asana-api-webhooks-verifying-x-hook-signature-in-node-ts/163484/7 "2022-08-08T05:44:35Z")

</div>

My code looks like this

```auto
const crypto = require("crypto");
const AWS = require('aws-sdk');

exports.handler = async (event, context) => {
    const ssm = new AWS.SSM();
    const name = "name_path_to_secret";
    const path = event.rawPath;
    const headers = event.headers;
    const body = event.body;
    let response;
    
    if(path == "/receiveWebhook") {
      if (headers["x-hook-secret"] != undefined) {
        console.log("This is a new webhook");
        const secret = headers["x-hook-secret"];
        const parameter = await ssm.putParameter({
          Name: name,
          Value: secret,
          KeyId: "my_key_id",
          Overwrite: true,
          Type: "SecureString"
        }).promise();
        
        response = {
          statusCode: 200,
          headers: {
            "X-Hook-Secret":secret,
          },
          body: null,
        }
      } else if (headers["x-hook-signature"] != undefined) {
        console.log("Webhook check");
            
        const parameter = await ssm.getParameter({ 
            Name: name, 
            WithDecryption: true 
        }).promise();
        const secret = parameter.Parameter.Value;
        
        const computedSignature = crypto
          .createHmac("SHA256", secret)
          .update(body)
          .digest("hex");
        if (
          !crypto.timingSafeEqual(
            Buffer.from(headers["x-hook-signature"]),
            Buffer.from(computedSignature)
          )
        ) {
          // Fail
          response = {
            statusCode: 401,
            body:null
          }
          console.log("Fail");
        } else {
          // Success
          response = {
            statusCode: 200,
            body:null
          }
          console.log("Success",event);
        }
      } else {
        console.error("Something went wrong!");
      }
    } 

    return response;
};

```

---

<div class="post-metadata">

**Author:** ![Karol\_Filipowicz](https://luna1.co/8d76cd.png) [@Karol\_Filipowicz](https://forum.asana.com/u/Karol_Filipowicz)\
**Post date:** [30 November 2022 09:50 UTC](https://forum.asana.com/t/asana-api-webhooks-verifying-x-hook-signature-in-node-ts/163484/8 "2022-11-30T09:50:25Z")

</div>

Hello!  
I’m facing a similar issue.  
Although, in my case the values sometimes match and other times don’t.  
I believe, it depends on the webhook filter criteria. Could you share yours, please, @anon55203160 or @Simon16?  
One, which works for me is for instance this:  
“filters”: [  
{  
“action”: “added”,  
“resource\_subtype”: “default\_task”,  
“resource\_type”: “task”  
}  
]  
One, which doesn’t work is this:  
“filters”: [  
{  
“action”: “changed”,  
“resource\_subtype”: “default\_task”,  
“resource\_type”: “task”  
}  
]  
The resource in both cases is the same project gid.  
I raised a support ticket (731830), which has been escalated, but no solution yet.

BR,  
Karol

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/system/32/276370_2.png) [@system](https://forum.asana.com/u/system)\
**Post date:** [30 May 2025 19:03 UTC](https://forum.asana.com/t/asana-api-webhooks-verifying-x-hook-signature-in-node-ts/163484/9 "2025-05-30T19:03:10Z")

</div>

Closed on 30 May 2025 19:03 UTC


