Server: forbid to make friends with a non https server

pull/24/head
Chocobozzz 2016-11-16 20:22:17 +01:00
parent 9c89a45cb2
commit 441b66f809
3 changed files with 15 additions and 2 deletions

View File

@ -6,7 +6,8 @@ const logger = require('./logger')
const utils = { const utils = {
cleanForExit, cleanForExit,
generateRandomString generateRandomString,
isTestInstance
} }
function generateRandomString (size, callback) { function generateRandomString (size, callback) {
@ -22,6 +23,10 @@ function cleanForExit (webtorrentProcess) {
process.kill(-webtorrentProcess.pid) process.kill(-webtorrentProcess.pid)
} }
function isTestInstance () {
return (process.env.NODE_ENV === 'test')
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
module.exports = utils module.exports = utils

View File

@ -152,7 +152,7 @@ const REQUEST_ENDPOINTS = {
const REMOTE_SCHEME = { const REMOTE_SCHEME = {
HTTP: 'https', HTTP: 'https',
WS: 'WS' WS: 'wss'
} }
// Password encryption // Password encryption
@ -220,6 +220,7 @@ module.exports = {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// This method exists in utils module but we want to let the constants module independent
function isTestInstance () { function isTestInstance () {
return (process.env.NODE_ENV === 'test') return (process.env.NODE_ENV === 'test')
} }

View File

@ -1,8 +1,10 @@
'use strict' 'use strict'
const checkErrors = require('./utils').checkErrors const checkErrors = require('./utils').checkErrors
const constants = require('../../initializers/constants')
const friends = require('../../lib/friends') const friends = require('../../lib/friends')
const logger = require('../../helpers/logger') const logger = require('../../helpers/logger')
const utils = require('../../helpers/utils')
const validatorsPod = { const validatorsPod = {
makeFriends, makeFriends,
@ -10,6 +12,11 @@ const validatorsPod = {
} }
function makeFriends (req, res, next) { function makeFriends (req, res, next) {
// Force https if the administrator wants to make friends
if (utils.isTestInstance() === false && constants.CONFIG.WEBSERVER.SCHEME === 'http') {
return res.status(400).send('Cannot make friends with a non HTTPS webserver.')
}
req.checkBody('hosts', 'Should have an array of unique hosts').isEachUniqueHostValid() req.checkBody('hosts', 'Should have an array of unique hosts').isEachUniqueHostValid()
logger.debug('Checking makeFriends parameters', { parameters: req.body }) logger.debug('Checking makeFriends parameters', { parameters: req.body })