From 6d071ae034f93b0a6d4cbbe7072310128c94f5eb Mon Sep 17 00:00:00 2001 From: bill bittner Date: Fri, 29 Jun 2018 11:25:59 -0700 Subject: [PATCH] changed social bot list to array --- .../assets/utils/determineRequestType.js | 22 ++++++++++++------- server/middleware/torCheckMiddleware.js | 1 - 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/server/controllers/assets/utils/determineRequestType.js b/server/controllers/assets/utils/determineRequestType.js index 4d3ce450..14a95657 100644 --- a/server/controllers/assets/utils/determineRequestType.js +++ b/server/controllers/assets/utils/determineRequestType.js @@ -3,26 +3,32 @@ const { EMBED, BROWSER, SOCIAL } = require('../constants/request_types.js'); function headersMatchesSocialBotList (headers) { const userAgent = headers['user-agent']; - const socialBotList = { - 'facebookexternalhit': 1, - 'Twitterbot' : 1, - }; - return socialBotList[userAgent]; + const socialBotList = [ + 'facebookexternalhit', + 'Twitterbot', + ]; + for (let i = 0; i < socialBotList.length; i++) { + if (userAgent.indexOf(socialBotList[i]) >= 0) { + logger.debug('request is from social bot:', socialBotList[i]); + return true; + } + } + return false; } function clientAcceptsHtml ({accept}) { return accept && accept.match(/text\/html/); -}; +} function requestIsFromBrowser (headers) { return headers['user-agent'] && headers['user-agent'].match(/Mozilla/); -}; +} function clientWantsAsset ({accept, range}) { const imageIsWanted = accept && accept.match(/image\/.*/) && !accept.match(/text\/html/) && !accept.match(/text\/\*/); const videoIsWanted = accept && range; return imageIsWanted || videoIsWanted; -}; +} const determineRequestType = (hasFileExtension, headers) => { let responseType; diff --git a/server/middleware/torCheckMiddleware.js b/server/middleware/torCheckMiddleware.js index 1b410331..1b24bfe7 100644 --- a/server/middleware/torCheckMiddleware.js +++ b/server/middleware/torCheckMiddleware.js @@ -12,7 +12,6 @@ const torCheck = (req, res, next) => { raw: true, }) .then(result => { - logger.debug('tor check results:', result); if (result.length >= 1) { logger.info('Tor request blocked:', ip); const failureResponse = {