Skip to content

Commit

Permalink
fix: #9348 incorrect redirect via connect-ensure-login
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlam committed Mar 4, 2021
1 parent b2c1b4a commit fbe9215
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ Controllers.login = async function (req, res) {
const loginStrategies = require('../routes/authentication').getLoginStrategies();
const registrationType = meta.config.registrationType || 'normal';
const allowLoginWith = (meta.config.allowLoginWith || 'username-email');
const returnTo = (req.headers['x-return-to'] || '').replace(nconf.get('base_url') + nconf.get('relative_path'), '');

let errorText;
if (req.query.error === 'csrf-invalid') {
Expand All @@ -106,10 +105,13 @@ Controllers.login = async function (req, res) {
errorText = validator.escape(String(req.query.error));
}

if (returnTo) {
req.session.returnTo = returnTo;
if (req.headers['x-return-to']) {
req.session.returnTo = req.headers['x-return-to'];
}

// Occasionally, x-return-to is passed a full url. Also, connect-ensure-login passes the relative path. Strip both.
req.session.returnTo = req.session.returnTo.replace(nconf.get('base_url'), '').replace(nconf.get('relative_path'), '');

data.alternate_logins = loginStrategies.length > 0;
data.authentication = loginStrategies;
data.allowRegistration = registrationType === 'normal';
Expand Down

0 comments on commit fbe9215

Please sign in to comment.