Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function handler(req, res) {
// https://cloud.google.com/functions/docs/writing/http
const body = isOnGoogleCloud() ? req.rawBody.toString() : req.body.toString();
console.log(`Request body: ${body}`);
try {
console.log(`X-Slack-Signature: ${req.get('X-Slack-Signature')}`);
// https://github.com/slackapi/node-slack-events-api/blob/v2.2.0/src/http-handler.js#L22-L58
verifyRequestSignature({
signingSecret: config.SLACK_SIGNING_SECRET,
requestSignature: req.get('X-Slack-Signature'),
requestTimestamp: req.get('X-Slack-Request-Timestamp'),
body: body
});
} catch (verificationErr) {
console.error(`Slack signature validation failed: ${verificationErr}`)
return res.status(401).json({ ok: false });
}
if (body.startsWith('{')) {
// application/json
const payload = JSON.parse(body);
if (payload.type === 'url_verification') {
// ------------------------------------
// Events API: url_verification