From 637006ab739ccf0c2b67ec4a8c90f2d1c00d807b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Rynning-T=C3=B8nnesen?= Date: Tue, 29 May 2018 19:37:22 +0200 Subject: [PATCH] Fixed some unhandled exceptions --- server/handlers/search.js | 2 +- server/routing/client/api.js | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/server/handlers/search.js b/server/handlers/search.js index 7961a416..8209064d 100644 --- a/server/handlers/search.js +++ b/server/handlers/search.js @@ -137,7 +137,7 @@ function findSimilar(msg, channel, broadcast, callback) { db.collection(channel).update({"id": msg.id}, { $set: element }, function(err, docs) { - if(docs.nModified == 1 && broadcast) { + if(docs && docs.hasOwnProperty("nModified") && docs.nModified == 1 && broadcast) { element.new_id = element.id; element.id = msg.id; if(!callback) { diff --git a/server/routing/client/api.js b/server/routing/client/api.js index 8828185f..8aecdba8 100644 --- a/server/routing/client/api.js +++ b/server/routing/client/api.js @@ -1203,9 +1203,13 @@ function incrementToken(token) { } router.route('/api/color').post(function(req, res) { - var origin = req.get("origin").replace("https://", "").replace("http://", ""); - var allowed = ["client.localhost", "localhost", "zoff.me", "client.zoff.me", "zoff.no", "client.zoff.no"]; - if(allowed.indexOf(origin) < 0) { + try { + var origin = req.get("origin").replace("https://", "").replace("http://", ""); + var allowed = ["client.localhost", "localhost", "zoff.me", "client.zoff.me", "zoff.no", "client.zoff.no"]; + if(allowed.indexOf(origin) < 0) { + throw "Wrong origin"; + } + } catch(e) { res.sendStatus(403); return; }