diff --git a/code/Global/Global.js b/code/Global/Global.js index 58a44e91..18322148 100644 --- a/code/Global/Global.js +++ b/code/Global/Global.js @@ -1467,3 +1467,7 @@ function getLinkCount(item) { } return (content.match(/https?:\/\//g) || []).length; } + +function getHrefScheme() { + return getProperty('hrefScheme', 'http') + '://'; +} diff --git a/code/HopObject/HopObject.js b/code/HopObject/HopObject.js index 5d0aa75c..b059f034 100644 --- a/code/HopObject/HopObject.js +++ b/code/HopObject/HopObject.js @@ -99,8 +99,8 @@ HopObject.prototype.onRequest = function() { // Checking if we are on the correct host to prevent at least some XSS issues if (req.action !== 'notfound' && req.action !== 'error' && this.href().contains('://') && - !this.href().toLowerCase().startsWith(req.servletRequest.scheme + - '://' + req.servletRequest.serverName.toLowerCase())) { + !this.href().toLowerCase().startsWith(getHrefScheme() + + req.servletRequest.serverName.toLowerCase())) { res.redirect(this.href(req.action === 'main' ? String.EMPTY : req.action)); } diff --git a/code/Site/Site.js b/code/Site/Site.js index 598f965e..05e9fe96 100644 --- a/code/Site/Site.js +++ b/code/Site/Site.js @@ -1049,15 +1049,18 @@ Site.prototype.getDiskSpace = function(quota) { * @param {String} href */ Site.prototype.processHref = function(href) { - var parts, domain, - scheme = (req.servletRequest ? req.servletRequest.scheme : 'http') + '://'; - if (domain = getProperty('domain.' + this.name)) { + var parts; + var scheme = getHrefScheme(); + var domain = getProperty('domain.' + this.name); + if (domain) { parts = [scheme, domain, href]; - } else if (domain = getProperty('domain.*')) { + } + domain = getProperty('domain.*'); + if (domain) { parts = [scheme, this.name, '.', domain, href]; } else { var mountpoint = app.appsProperties.mountpoint; - (mountpoint === '/') && (mountpoint = ''); // Prevents double slashes + if (mountpoint === '/') mountpoint = ''; // Prevents double slashes parts = [scheme, req.data.http_host, mountpoint, href]; } return parts.join(''); @@ -1113,11 +1116,11 @@ Site.prototype.getStaticFile = function(tail) { * @returns {String} */ Site.prototype.getStaticUrl = function(href) { - href || (href = ''); - var scheme = (req.servletRequest ? req.servletRequest.scheme : 'http') + '://'; + if (!href) href = ''; + var scheme = getHrefScheme(); var host = getProperty('domain.' + this.name); - host || (host = getProperty('domain.*')); - host || (host = req.data.http_host); + if (!host) host = getProperty('domain.*'); + if (!host) host = req.data.http_host; return [scheme, host, app.appsProperties.staticMountpoint, '/sites/', this.name, '/', href].join(''); } diff --git a/code/app.properties b/code/app.properties index 0662ff17..a0d100ea 100644 --- a/code/app.properties +++ b/code/app.properties @@ -47,6 +47,7 @@ cron.nightly.minute = 0 baseUri = / hrefFunction = processHref #hrefRootPrototype = Site +#hrefScheme = https # List of default and individual domain mappings #domain.* = antville.org