v1.18.x
Julian Lam 9 years ago
parent de49de3c56
commit 60ea7d5121

@ -103,6 +103,8 @@ function loadConfig() {
nconf.set('themes_path', path.resolve(__dirname, nconf.get('themes_path'))); nconf.set('themes_path', path.resolve(__dirname, nconf.get('themes_path')));
nconf.set('core_templates_path', path.join(__dirname, 'src/views')); nconf.set('core_templates_path', path.join(__dirname, 'src/views'));
nconf.set('base_templates_path', path.join(nconf.get('themes_path'), 'nodebb-theme-persona/templates')); nconf.set('base_templates_path', path.join(nconf.get('themes_path'), 'nodebb-theme-persona/templates'));
nconf.set('url_parsed', url.parse(nconf.get('url')));
} }

@ -334,9 +334,7 @@ $(document).ready(function() {
return; return;
} }
var internalLink = this.host === '' || // Relative paths are always internal links var internalLink = utils.isInternalURI(this, window.location, RELATIVE_PATH);
(this.host === window.location.host && this.protocol === window.location.protocol && // Otherwise need to check if protocol and host match
(RELATIVE_PATH.length > 0 ? this.pathname.indexOf(RELATIVE_PATH) === 0 : true)); // Subfolder installs need this additional check
if ($(this).attr('data-ajaxify') === 'false') { if ($(this).attr('data-ajaxify') === 'false') {
if (!internalLink) { if (!internalLink) {

@ -431,6 +431,14 @@
} }
return utils.props(obj[prop], newProps, value); return utils.props(obj[prop], newProps, value);
},
isInternalURI: function(targetLocation, referenceLocation, relative_path) {
return targetLocation.host === '' || // Relative paths are always internal links
(
targetLocation.host === referenceLocation.host && targetLocation.protocol === referenceLocation.protocol && // Otherwise need to check if protocol and host match
(relative_path.length > 0 ? targetLocation.pathname.indexOf(relative_path) === 0 : true) // Subfolder installs need this additional check
);
} }
}; };

@ -6,6 +6,7 @@ var passport = require('passport');
var nconf = require('nconf'); var nconf = require('nconf');
var validator = require('validator'); var validator = require('validator');
var _ = require('underscore'); var _ = require('underscore');
var url = require('url');
var db = require('../database'); var db = require('../database');
var meta = require('../meta'); var meta = require('../meta');
@ -168,7 +169,7 @@ authenticationController.registerComplete = function(req, res, next) {
} else { } else {
res.redirect(nconf.get('relative_path') + '/'); res.redirect(nconf.get('relative_path') + '/');
} }
} };
async.parallel(callbacks, function(err) { async.parallel(callbacks, function(err) {
if (err) { if (err) {
@ -187,7 +188,7 @@ authenticationController.registerComplete = function(req, res, next) {
}); });
}; };
authenticationController.registerAbort = function(req, res, next) { authenticationController.registerAbort = function(req, res) {
// End the session and redirect to home // End the session and redirect to home
req.session.destroy(function() { req.session.destroy(function() {
res.redirect(nconf.get('relative_path') + '/'); res.redirect(nconf.get('relative_path') + '/');
@ -197,7 +198,11 @@ authenticationController.registerAbort = function(req, res, next) {
authenticationController.login = function(req, res, next) { authenticationController.login = function(req, res, next) {
// Handle returnTo data // Handle returnTo data
if (req.body.hasOwnProperty('returnTo') && !req.session.returnTo) { if (req.body.hasOwnProperty('returnTo') && !req.session.returnTo) {
req.session.returnTo = req.body.returnTo; // As req.body is data obtained via userland, it is untrusted, restrict to internal links only
var parsed = url.parse(req.body.returnTo);
var isInternal = utils.isInternalURI(url.parse(req.body.returnTo), nconf.get('url_parsed'), nconf.get('relative_path'));
req.session.returnTo = isInternal ? req.body.returnTo : nconf.get('url');
} }
if (plugins.hasListeners('action:auth.overrideLogin')) { if (plugins.hasListeners('action:auth.overrideLogin')) {

Loading…
Cancel
Save