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

Commit

Permalink
Merge pull request #1539 from danhofer/master
Browse files Browse the repository at this point in the history
use hmac compare instead of direct compare
  • Loading branch information
benbrown authored Dec 14, 2018
2 parents aab39e8 + ee7b1b0 commit 60de572
Showing 1 changed file with 13 additions and 1 deletion.
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

0 comments on commit 60de572

Please sign in to comment.