Merge branch 'safer-redirects' into 'master'

safer redirects with login/logout

See merge request fatchan/jschan!170
merge-requests/208/head
Thomas Lynch 4 years ago
commit fed813d50f
  1. 2
      helpers/checks/isloggedin.js
  2. 8
      models/forms/login.js

@ -7,7 +7,7 @@ module.exports = async (req, res, next) => {
let goto;
if (req.method === 'GET' && req.path) {
//coming from a GET page isLoggedIn middleware check
goto = req.path;
goto = encodeURIComponent(req.path);
}
return res.redirect(`/login.html${goto ? '?goto='+goto : ''}`);
}

@ -8,8 +8,12 @@ module.exports = async (req, res, next) => {
const username = req.body.username.toLowerCase();
const password = req.body.password;
const goto = req.body.goto || '/account.html';
const failRedirect = `/login.html${goto ? '?goto='+goto : ''}`
let goto = req.body.goto;
// we don't want to redirect the user to random sites
if (goto == null || !/^\/[0-9a-zA-Z][0-9a-zA-Z._/-]*$/.test(goto)) {
goto = '/account.html';
}
const failRedirect = `/login.html${goto ? '?goto='+encodeURIComponent(goto) : ''}`
//fetch an account
const account = await Accounts.findOne(username);

Loading…
Cancel
Save