From 79087b27d3ca05d02927212fa18de03bffa9aebd Mon Sep 17 00:00:00 2001 From: aszlig Date: Fri, 18 May 2018 17:02:36 +0200 Subject: [PATCH] redirects: Fix parsing BASE_URL with port number (#10350) The parsing in the redirects module was simply determining the base host via trimming off everything up to //, so a BASE_URL like "http://localhost:3000" will result in the host name "localhost:3000", which isn't a valid host name. So the problem here is that BASE_URL_HOST is used for determining whether the client should be redirected and it's comparing the hostname of the request object with BASE_URL_HOST. For example if we have the aforementioned BASE_URL, we get to the following comparison: req.hostname !== BASE_URL_HOST Which expands to: "localhost" !== "localhost:3000" So in order to get rid of the port number, we now use url.parse() to get the right host name. Signed-off-by: aszlig --- website/server/middlewares/redirects.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/server/middlewares/redirects.js b/website/server/middlewares/redirects.js index 9bc40cb439..0de427c2e9 100644 --- a/website/server/middlewares/redirects.js +++ b/website/server/middlewares/redirects.js @@ -1,11 +1,11 @@ import nconf from 'nconf'; +import url from 'url'; const IS_PROD = nconf.get('IS_PROD'); const IGNORE_REDIRECT = nconf.get('IGNORE_REDIRECT') === 'true'; const BASE_URL = nconf.get('BASE_URL'); -let baseUrlSplit = BASE_URL.split('//'); -const BASE_URL_HOST = baseUrlSplit[1]; +const BASE_URL_HOST = url.parse(BASE_URL).hostname; function isHTTP (req) { return ( // eslint-disable-line no-extra-parens