Tor middleware #499

Merged
bones7242 merged 16 commits from tor-middleware into master 2018-06-29 02:59:56 +02:00
2 changed files with 17 additions and 13 deletions
Showing only changes of commit a46b157fe1 - Show all commits

View file

@ -1,3 +1,5 @@
const logger = require('winston');
const { details: { host }, publishing: { disabled, disabledMessage } } = require('@config/siteConfig');
const { sendGATimingEvent } = require('../../../../utils/googleAnalytics.js');
@ -19,7 +21,7 @@ const authenticateUser = require('./authentication.js');
*/
const claimPublish = ({ body, files, headers, ip, originalUrl, user }, res) => {
const claimPublish = ({ body, files, headers, ip, originalUrl, user, tor }, res) => {
// check for disabled publishing
if (disabled) {
return res.status(503).json({
@ -27,6 +29,16 @@ const claimPublish = ({ body, files, headers, ip, originalUrl, user }, res) => {
message: disabledMessage
});
}
// check for tor
logger.debug('tor:', tor);
if (tor) {
const failureResponse = {
success: 'false',
message: 'Unfortunately this api route is not currently available for tor users. We are working on a solution that will allow tor users to use this endpoint in the future.',
};
return res.status(400).json(failureResponse);
}
// define variables
let channelName, channelId, channelPassword, description, fileName, filePath, fileType, gaStartTime, license, name, nsfw, thumbnail, thumbnailFileName, thumbnailFilePath, thumbnailFileType, title;
// record the start time of the request

View file

@ -1,7 +1,8 @@
neb-b commented 2018-06-28 23:38:26 +02:00 (Migrated from github.com)
Review

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.
bones7242 commented 2018-06-29 02:22:00 +02:00 (Migrated from github.com)
Review

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.
neb-b commented 2018-06-28 23:38:26 +02:00 (Migrated from github.com)
Review

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.
bones7242 commented 2018-06-29 02:22:00 +02:00 (Migrated from github.com)
Review

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.
const logger = require('winston');
const db = require('../models');
const torCheck = ({ ip, headers, body }, res, next) => {
neb-b commented 2018-06-28 23:38:26 +02:00 (Migrated from github.com)
Review

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.
bones7242 commented 2018-06-29 02:22:00 +02:00 (Migrated from github.com)
Review

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.
const torCheck = (req, res, next) => {
neb-b commented 2018-06-28 23:38:26 +02:00 (Migrated from github.com)
Review

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.
bones7242 commented 2018-06-29 02:22:00 +02:00 (Migrated from github.com)
Review

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.
const { ip } = req;
neb-b commented 2018-06-28 23:38:26 +02:00 (Migrated from github.com)
Review

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.
bones7242 commented 2018-06-29 02:22:00 +02:00 (Migrated from github.com)
Review

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.
logger.debug(`tor check for: ${ip}`);
return db.Tor.findAll(
{
@ -12,17 +13,8 @@ const torCheck = ({ ip, headers, body }, res, next) => {
neb-b commented 2018-06-28 23:38:26 +02:00 (Migrated from github.com)
Review

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.
bones7242 commented 2018-06-29 02:22:00 +02:00 (Migrated from github.com)
Review

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.
neb-b commented 2018-06-28 23:38:26 +02:00 (Migrated from github.com)
Review

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.
bones7242 commented 2018-06-29 02:22:00 +02:00 (Migrated from github.com)
Review

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.
})
.then(result => {
logger.debug('tor check results:', result);
if (result.length >= 1) {
neb-b commented 2018-06-28 23:38:26 +02:00 (Migrated from github.com)
Review

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.
bones7242 commented 2018-06-29 02:22:00 +02:00 (Migrated from github.com)
Review

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.
logger.debug('this is a tor ip');
neb-b commented 2018-06-28 23:38:26 +02:00 (Migrated from github.com)
Review

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.
bones7242 commented 2018-06-29 02:22:00 +02:00 (Migrated from github.com)
Review

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.
const failureResponse = {
neb-b commented 2018-06-28 23:38:26 +02:00 (Migrated from github.com)
Review

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.
bones7242 commented 2018-06-29 02:22:00 +02:00 (Migrated from github.com)
Review

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.
success: 'false',
neb-b commented 2018-06-28 23:38:26 +02:00 (Migrated from github.com)
Review

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.
bones7242 commented 2018-06-29 02:22:00 +02:00 (Migrated from github.com)
Review

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.
message: 'Unfortunately this api route is not currently available for tor users. We are working on a solution that will allow tor users to use this endpoint in the future.',
neb-b commented 2018-06-28 23:38:26 +02:00 (Migrated from github.com)
Review

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.
bones7242 commented 2018-06-29 02:22:00 +02:00 (Migrated from github.com)
Review

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.
};
neb-b commented 2018-06-28 23:38:26 +02:00 (Migrated from github.com)
Review

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.
bones7242 commented 2018-06-29 02:22:00 +02:00 (Migrated from github.com)
Review

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.
return res.status(400).json(failureResponse);
neb-b commented 2018-06-28 23:38:26 +02:00 (Migrated from github.com)
Review

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.
bones7242 commented 2018-06-29 02:22:00 +02:00 (Migrated from github.com)
Review

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.
} else {
neb-b commented 2018-06-28 23:38:26 +02:00 (Migrated from github.com)
Review

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.
bones7242 commented 2018-06-29 02:22:00 +02:00 (Migrated from github.com)
Review

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.
logger.debug('this is not a tor ip');
neb-b commented 2018-06-28 23:38:26 +02:00 (Migrated from github.com)
Review

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.
bones7242 commented 2018-06-29 02:22:00 +02:00 (Migrated from github.com)
Review

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.
return next();
neb-b commented 2018-06-28 23:38:26 +02:00 (Migrated from github.com)
Review

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.
bones7242 commented 2018-06-29 02:22:00 +02:00 (Migrated from github.com)
Review

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.
}
neb-b commented 2018-06-28 23:38:26 +02:00 (Migrated from github.com)
Review

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.
bones7242 commented 2018-06-29 02:22:00 +02:00 (Migrated from github.com)
Review

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.
req['tor'] = (result.length >= 1); // add this to the req object
neb-b commented 2018-06-28 23:38:26 +02:00 (Migrated from github.com)
Review

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.
bones7242 commented 2018-06-29 02:22:00 +02:00 (Migrated from github.com)
Review

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.
next();
neb-b commented 2018-06-28 23:38:26 +02:00 (Migrated from github.com)
Review

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.
bones7242 commented 2018-06-29 02:22:00 +02:00 (Migrated from github.com)
Review

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.
})
.catch(error => {
logger.error(error);

neb-b commented 2018-06-28 23:38:26 +02:00 (Migrated from github.com)
Review

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.
bones7242 commented 2018-06-29 02:22:00 +02:00 (Migrated from github.com)
Review

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.
neb-b commented 2018-06-28 23:38:26 +02:00 (Migrated from github.com)
Review

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.

Maybe you should just stop the request here? Not sure, if there are other routes in that may be blocked in the future it will be simpler to add. If it's gonna be only the /publish route then this is probably fine.
bones7242 commented 2018-06-29 02:22:00 +02:00 (Migrated from github.com)
Review

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.

Yeah, I think that would be the better way to handle it. That way the middleware can be placed on any route and response is handled from the middleware, rather than having to handle in all the routes.