Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validateMessageIntegrity method doesn't use the payload body #98

Open
toddheslin opened this issue May 10, 2020 · 2 comments
Open

validateMessageIntegrity method doesn't use the payload body #98

toddheslin opened this issue May 10, 2020 · 2 comments

Comments

@toddheslin
Copy link

I've noticed that when creating the hash here:

const authenticationCode = createHmac(xHubSignatureValueParts[0], fbApplicationSecret).digest('hex');

You aren't updating with the payload body. Are you using this successfully in production for an older version of the API? The current API version requires using the payload to verify the request:

To validate the payload:

1. Generate a SHA1 signature using the payload and your app's App Secret.
2. Compare your signature to the signature in the X-Hub-Signature header (everything after sha1=). If the signatures match, the payload is genuine.

https://developers.facebook.com/docs/graph-api/webhooks/getting-started#verification-requests

@crisboarna
Copy link
Owner

crisboarna commented May 12, 2020

You are correct, good catch, using wrong entity for sha creation. Will release a fix for this tomorrow :)

@toddheslin
Copy link
Author

I'm not sure if there is a great way of creating the payload buffer in a framework agnostic way. There is the express way: https://github.com/expressjs/body-parser#bodyparserrawoptions

But I use Fastify as a framework so I'd like the option of either just passing in the buffer (not actually supported in Fastify without a few tricks...yet), or perhaps just passing in the body object which could be turned back into a buffer for the check. I doubt this is the most performant way but not sure if it's really a big deal.

Probably the only thing I'd urge against is making any assumptions on the framework. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants