Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

use hmac compare instead of direct compare #1539

Merged
merged 2 commits into from
Dec 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/SlackBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,20 @@ function Slackbot(configuration) {
.update(basestring)
.digest('hex');
let retrievedSignature = req.header('X-Slack-Signature');

// Compare the hash of the computed signature with the retrieved signature with a secure hmac compare function
const validSignature = () => {

const crypto = require('crypto');

if (hash !== retrievedSignature) {
const slackSigBuffer = new Buffer(retrievedSignature);
const compSigBuffer = new Buffer(hash);

return crypto.timingSafeEqual(slackSigBuffer, compSigBuffer);
}

// replace direct compare with the hmac result
if (!validSignature()) {
slack_botkit.debug('Signature verification failed, Ignoring message');
res.status(401);
return;
Expand Down