]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Server: forbid to make friends with a non https server
authorChocobozzz <florian.bigard@gmail.com>
Wed, 16 Nov 2016 19:22:17 +0000 (20:22 +0100)
committerChocobozzz <florian.bigard@gmail.com>
Wed, 16 Nov 2016 19:29:26 +0000 (20:29 +0100)
server/helpers/utils.js
server/initializers/constants.js
server/middlewares/validators/pods.js

index 9c2d402e3105047615d26bfe4ebd016deed2810d..9f27671b6f5712b8550dbfe4c5b378d6e703af66 100644 (file)
@@ -6,7 +6,8 @@ const logger = require('./logger')
 
 const utils = {
   cleanForExit,
-  generateRandomString
+  generateRandomString,
+  isTestInstance
 }
 
 function generateRandomString (size, callback) {
@@ -22,6 +23,10 @@ function cleanForExit (webtorrentProcess) {
   process.kill(-webtorrentProcess.pid)
 }
 
+function isTestInstance () {
+  return (process.env.NODE_ENV === 'test')
+}
+
 // ---------------------------------------------------------------------------
 
 module.exports = utils
index 40e1c5381c9968e3215a630fdd5dd22ceb1f5c21..3ddf87454e0e234ffaf3215cfd6c2fa0f088c9c1 100644 (file)
@@ -152,7 +152,7 @@ const REQUEST_ENDPOINTS = {
 
 const REMOTE_SCHEME = {
   HTTP: 'https',
-  WS: 'WS'
+  WS: 'wss'
 }
 
 // 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 () {
   return (process.env.NODE_ENV === 'test')
 }
index 4f8bad2f9610cd0ce311b43b4b0933d4d78e04ed..0723871b2ca3499c5504b4fbc156ae4276250fc6 100644 (file)
@@ -1,8 +1,10 @@
 'use strict'
 
 const checkErrors = require('./utils').checkErrors
+const constants = require('../../initializers/constants')
 const friends = require('../../lib/friends')
 const logger = require('../../helpers/logger')
+const utils = require('../../helpers/utils')
 
 const validatorsPod = {
   makeFriends,
@@ -10,6 +12,11 @@ const validatorsPod = {
 }
 
 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()
 
   logger.debug('Checking makeFriends parameters', { parameters: req.body })