question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Cannot validate webhook

See original GitHub issue

Bug Report

Describe the bug There is an error during Webhook validation (the code used to work previously) This happened in middleware when /webhook was called

To Reproduce

Steps to reproduce the behavior: 0. You may or may not use the code from my repo (https://github.com/gie3d/nonglinebot)

  1. Used node line bot sdk and created a /webhook that looks like this
app.post('/webhook', line.middleware(config), (req, res) => {
    Promise
        .all(req.body.events.map(handleEvent))
        .then((result) => res.json(result));
});
  1. Test webhook from Line developers website and check the log
2020-06-15T08:15:23.078099+00:00 heroku[router]: at=info method=POST path="/webhook" host=qline2020.herokuapp.com request_id=5b01db7e-532a-436b-8ba5-c55993174f61 fwd="203.104.156.74" dyno=web.1 connect=1ms service=23ms status=500 bytes=404 protocol=https
2020-06-15T08:15:23.079280+00:00 app[web.1]: TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Object
2020-06-15T08:15:23.079323+00:00 app[web.1]:     at Hmac.update (internal/crypto/hash.js:82:11)
2020-06-15T08:15:23.079324+00:00 app[web.1]:     at Object.validateSignature [as default] (/app/node_modules/@line/bot-sdk/dist/validate-signature.js:14:69)
2020-06-15T08:15:23.079325+00:00 app[web.1]:     at _middleware (/app/node_modules/@line/bot-sdk/dist/middleware.js:36:42)
2020-06-15T08:15:23.079326+00:00 app[web.1]:     at processTicksAndRejections (internal/process/task_queues.js:97:5)

The error seems to happen in validate-signature and the type of data seems to be incorrect but I can’t investigate any further.

Expected behavior There should be no error

Environment (please complete the following information):

  • OS: Mac OS X 10.15.5
  • Node.js 12.6.0
  • line-bot-sdk-nodejs 6.8.4

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
gie3dcommented, Jun 16, 2020

Thanks @xingoxu @EriecTanijaya, it really was because of the body-parser. My apologise, the code I pushed to heroku was a little different from the git as I didn’t push it to my github repo 😥

Changing from

app.use(bodyParser.json());
app.use('/webhook', line.middleware(config));

app.post('/webhook', (req, res) => {
	Promise.all(req.body.events.map(handleLineWebHook)).then((result) => res.json(result));
});

to

app.use('/webhook', line.middleware(config));
app.use(bodyParser.json());

app.post('/webhook', (req, res) => {
	Promise.all(req.body.events.map(handleLineWebHook)).then((result) => res.json(result));
});

as suggested in https://line.github.io/line-bot-sdk-nodejs/guide/webhook.html#build-a-webhook-server-with-express did solve the problem.

Many thanks 👍

1reaction
xingoxucommented, Jun 15, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cant validate webhook curl error number 60
To solve this problem you have to install ssl chain certificate. You will get full chain certificate by combining your site Certificate (CRT)...
Read more >
Sharepoint webhooks - Failed to validate the notification URL
It seems like SharePoint cannot validate the Webhook. Does your Endpoint return the validationtoken within 5 Seconds, i.e.
Read more >
Complete Guide to Troubleshooting and Debugging Webhooks
Learn what brings bugs in the process of developing with webhooks, how to tackle these bugs, and tools that can help the troubleshooting...
Read more >
Error on Signing Secret Webhook Stripe - WordPress.org
Hi,. Everytime I add the signing secret for Stripe, it seems to return an error in the console log. “Uncaught (in promise) TypeError:...
Read more >
Handle errors | Stripe Documentation
If an immediate problem prevents an API call from continuing, the Stripe Ruby ... You're using webhook signature verification and couldn't verify that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found