Server fixes.

Ylian Saint-Hilaire committed Jun 21, 2020 at 14:27 UTC 923d85a5b92de0a08357cfbe8022e71f915bc9e1
3 files changed +7 -4
meshuser.js
+1
@@ -4074,6 +4074,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
4074 case 'userWebState': {
4075 if (common.validateString(command.state, 1, 10000) == false) break; // Check state size, no more than 10k
4076 command.state = parent.filterUserWebState(command.state); // Filter the state to remove anything bad
4077 + if ((command.state == null) || (typeof command.state !== 'object')) break; // If state did not validate correctly, quit here.
4078 db.Set({ _id: 'ws' + user._id, state: command.state });
4079 parent.parent.DispatchEvent([user._id], obj, { action: 'userWebState', nolog: 1, domain: domain.id, state: command.state });
4080 break;
views/default.handlebars
+1
@@ -1188,6 +1188,7 @@
1188 // Process server-side web state
1189 var webState = '{{{webstate}}}';
1190 if (webState != '') { webState = JSON.parse(decodeURIComponent(webState)); }
1191 + if ((webState == null) || (typeof webState != 'object')) { webState = {}; }
1192 for (var i in webState) { if (i != 'desktopsettings') { localStorage.setItem(i, webState[i]); } }
1193 if (!webState.loctag) { try { delete localStorage.removeItem('loctag'); } catch (ex) { } }
1194
webserver.js
+5 -4
@@ -1747,9 +1747,9 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
1747 if (!user) { parent.debug('web', 'handleDeleteAccountRequest: user not found.'); res.sendStatus(404); return; }
1748
1749 // Check if the password is correct
1750 - obj.authenticate(user.name, req.body.apassword1, domain, function (err, userid) {
1750 + obj.authenticate(user._id.split('/')[2], req.body.apassword1, domain, function (err, userid) {
1751 var deluser = obj.users[userid];
1752 - if ((deluser != null) || (userid == null)) {
1752 + if ((userid != null) && (deluser != null)) {
1753 // Remove all links to this user
1754 if (deluser.links != null) {
1755 for (var i in deluser.links) {
@@ -2813,10 +2813,10 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
2813 // Download a desktop recording
2814 function handleGetRecordings(req, res) {
2815 const domain = checkUserIpAddress(req, res);
2816 - if (domain == null) { return; }
2816 + if (domain == null) return;
2817
2818 // Check the query
2819 - if (req.query.file == null) { res.sendStatus(401); return; }
2819 + if ((req.query.file == null) || (obj.common.IsFilenameValid(req.query.file) !== true)) { res.sendStatus(401); return; }
2820
2821 // Get the recording path
2822 var recordingsPath = null;
@@ -5608,6 +5608,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
5608 const acceptableUserWebStateDesktopStrings = ['encoding', 'showfocus', 'showmouse', 'showcad', 'limitFrameRate', 'noMouseRotate', 'quality', 'scaling']
5609 obj.filterUserWebState = function (state) {
5610 if (typeof state == 'string') { try { state = JSON.parse(state); } catch (ex) { return null; } }
5611 + if ((state == null) || (typeof state != 'object')) { return null; }
5612 var out = {};
5613 for (var i in acceptableUserWebStateStrings) {
5614 var n = acceptableUserWebStateStrings[i];