Skip to content

Commit

Permalink
refactor: light refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
billchurch committed May 20, 2022
1 parent 0dcaa6e commit e75392b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const session = require('express-session')(config.express);

const appSocket = require('./socket');
const { setDefaultCredentials, basicAuth } = require('./util');
const { webssh2debug, auditLog, logError } = require('./logging');
const { webssh2debug } = require('./logging');
const { reauth, connect, notfound, handleErrors } = require('./routes');

setDefaultCredentials(config);
Expand Down
14 changes: 8 additions & 6 deletions app/server/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ const config = require('./config');

exports.reauth = function reauth(req, res) {
let { referer } = req.headers;
console.log(`referer: ${referer}`);
if (!validator.isURL(referer, { host_whitelist: ['localhost'] })) referer = '/';
console.log(`referer: ${referer}`);

if (!validator.isURL(referer, { host_whitelist: ['localhost'] })) {
console.error(
`WebSSH2 (${req.sessionID}) ERROR: Referrer '${referer}' for '/reauth' invalid. Setting to '/' which will probably fail.`
);
referer = '/';
}
res
.status(401)
.send(
Expand Down Expand Up @@ -87,11 +89,11 @@ exports.connect = function connect(req, res) {
if (req.session.ssh.header.background) validator.escape(req.session.ssh.header.background);
};

exports.notfound = function notfound(req, res) {
exports.notfound = function notfound(_req, res) {
res.status(404).send("Sorry, can't find that!");
};

exports.handleErrors = function handleErrors(err, req, res) {
exports.handleErrors = function handleErrors(err, _req, res) {
console.error(err.stack);
res.status(500).send('Something broke!');
};

0 comments on commit e75392b

Please sign in to comment.