From 3cedf474e5611e91f8cdf132999e385270d3ab50 Mon Sep 17 00:00:00 2001 From: Muh Muhten Date: Sat, 28 Jul 2018 04:38:17 -0400 Subject: [PATCH] Fix misparse of port when binding Unix socket The hostname:port of URIs used in Minify are currently bogus and refer to localhost only for historical reasons; there's no reason to retain them and omitting them avoids generating an invalid URI when "port" is not an integer. Context: settings.port is passed to express's listen; if not numeric, it is used a filename for a Unix domain socket. This allows e.g. starting a server to be reverse-proxied on a multi-user system, using the filesystem to handle access control and avoiding need to allocate port numbers. Before this change, etherpad-lite starts without error when configured to listen on a Unix domain socket in this manner. However, `pad.js` and `ace2_common.js` are generated incorrecting, causing an error "Uncaught Error: The module at "ep_etherpad-lite/static/js/rjquery" does not exist." when loading the editor: When settings.port is a non-numeric string, e.g. `etherpad.sock`, a URI of the form `http://localhost:etherpad.sock/static/js/rjquery.js` is generated and parsed to find the file needed. In this case, the file searched for is `:etherpad.sock/static/js/rjquery.js`, rather than the expected `static/js/rjquery.js`. No such file exists, and the required code is silently omitted from the bundle. As a workaround, hard-code a (meaningless) hostname which can be parsed correctly, since the current code makes no use of it anyway. --- src/node/hooks/express/static.js | 5 +++-- src/node/utils/Minify.js | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/node/hooks/express/static.js b/src/node/hooks/express/static.js index 34fce29ed..ef41865e3 100644 --- a/src/node/hooks/express/static.js +++ b/src/node/hooks/express/static.js @@ -17,11 +17,12 @@ exports.expressCreateServer = function (hook_name, args, cb) { // Setup middleware that will package JavaScript files served by minify for // CommonJS loader on the client-side. + // Hostname "invalid.invalid" is a dummy value to allow parsing as a URI. var jsServer = new (Yajsml.Server)({ rootPath: 'javascripts/src/' - , rootURI: 'http://localhost:' + settings.port + '/static/js/' + , rootURI: 'http://invalid.invalid/static/js/' , libraryPath: 'javascripts/lib/' - , libraryURI: 'http://localhost:' + settings.port + '/static/plugins/' + , libraryURI: 'http://invalid.invalid/static/plugins/' , requestURIs: minify.requestURIs // Loop-back is causing problems, this is a workaround. }); diff --git a/src/node/utils/Minify.js b/src/node/utils/Minify.js index a56e347db..4596f404c 100644 --- a/src/node/utils/Minify.js +++ b/src/node/utils/Minify.js @@ -264,7 +264,8 @@ function getAceFile(callback) { async.forEach(founds, function (item, callback) { var filename = item.match(/"([^"]*)"/)[1]; - var baseURI = 'http://localhost:' + settings.port; + // Hostname "invalid.invalid" is a dummy value to allow parsing as a URI. + var baseURI = 'http://invalid.invalid'; var resourceURI = baseURI + path.normalize(path.join('/static/', filename)); resourceURI = resourceURI.replace(/\\/g, '/'); // Windows (safe generally?)