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

Fixing api token and updating to resolve vulverabilities #166

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
15 changes: 11 additions & 4 deletions lib/slack.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Module dependencies.
*/

var util = require("util");
var cheerio = require('cheerio');
var thunkify = require('thunkify-wrap');
var request = thunkify(require('request'));
Expand All @@ -24,7 +24,7 @@ module.exports = Slack;

var loginFormPath = '/?no_sso=1';
var emojiAddEndpoint = '/api/emoji.add';
var apiTokenRegex = new RegExp('api_token: "(.*)"');
var apiTokenRegex = new RegExp('"api_token":"((\\"|[^"])*)"');

// required to avoid "This browser is not supported" message
var headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'};
Expand Down Expand Up @@ -53,7 +53,9 @@ function Slack(opts, debug) {
console.log('Uh oh! ' + e);
throw e;
}

console.log('Getting emoji page');

var emojiList = '';
var aliasList = '';
for (var i = 0; i < Object.keys(this.opts.emojis).length; i++) {
Expand All @@ -69,8 +71,10 @@ function Slack(opts, debug) {
}
}
}

console.log('Uploaded emojis:' + emojiList);
console.log('Uploaded emoji aliases:' + aliasList);

return 'Success';
};

Expand Down Expand Up @@ -99,6 +103,7 @@ function Slack(opts, debug) {
password: opts.password
};
if (!opts.formData.signin && !opts.formData.redir && !opts.formData.crumb) throw new Error('Login error: could not get login form for ' + opts.url);

return this.opts = opts;
};

Expand Down Expand Up @@ -152,10 +157,12 @@ function Slack(opts, debug) {

//TODO: it may be necessary in the future to replace this with a user-supplied token
var match = apiTokenRegex.exec(res[0].body);
if (!match || !match[1]) {
var result = match[0].split('"');

if (!result[3]) {
throw new Error('Application Error: unable to find api token on login page');
}
opts.apiToken = match[1];
opts.apiToken = result[3];

return this.opts = opts;
};
Expand Down
Loading