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

apply verification middleware only on the webhook endpoint #1203

Merged
merged 2 commits into from
Jan 18, 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
17 changes: 8 additions & 9 deletions lib/SlackBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,31 +101,30 @@ function Slackbot(configuration) {


// adds the webhook authentication middleware module to the webserver
function secureWebhookEndpoints() {
function secureWebhookEndpoints(webserver, endpoint, tokens) {
var authenticationMiddleware = require(__dirname + '/middleware/slack_authentication.js');
// convert a variable argument list to an array, drop the webserver argument
var tokens = Array.prototype.slice.call(arguments);
var webserver = tokens.shift();


slack_botkit.log(
'** Requiring token authentication for webhook endpoints for Slash commands ' +
'and outgoing webhooks; configured ' + tokens.length + ' token(s)'
);

webserver.use(authenticationMiddleware(tokens));
webserver.use(endpoint, authenticationMiddleware(tokens));
}

// set up a web route for receiving outgoing webhooks and/or slash commands
slack_botkit.createWebhookEndpoints = function(webserver, authenticationTokens) {

var endpoint = '/slack/receive';
if (authenticationTokens !== undefined && arguments.length > 1 && arguments[1].length) {
secureWebhookEndpoints.apply(null, arguments);
//botkit allows an array of tokens or multiple tokens as variable length params
var tokens = Array.prototype.slice.call(arguments, 1);
secureWebhookEndpoints(webserver, endpoint, tokens);
}

slack_botkit.log(
'** Serving webhook endpoints for Slash commands and outgoing ' +
'webhooks at: http://' + slack_botkit.config.hostname + ':' + slack_botkit.config.port + '/slack/receive');
webserver.post('/slack/receive', function(req, res) {
webserver.post(endpoint, function(req, res) {

// respond to Slack that the webhook has been received.
res.status(200);
Expand Down