From 39f87cb21689a912559d0498641db7d2de4a784d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 23 Aug 2016 14:37:36 +0200 Subject: Server: catch JSON.parse exceptions --- server/lib/friends.js | 7 ++++++- server/middlewares/secure.js | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'server') diff --git a/server/lib/friends.js b/server/lib/friends.js index 667055d4c..6c4383d8e 100644 --- a/server/lib/friends.js +++ b/server/lib/friends.js @@ -198,7 +198,12 @@ function getForeignPodsList (url, callback) { request.get(url + path, function (err, response, body) { if (err) return callback(err) - callback(null, JSON.parse(body)) + try { + const json = JSON.parse(body) + return callback(null, json) + } catch (err) { + return callback(err) + } }) } diff --git a/server/middlewares/secure.js b/server/middlewares/secure.js index 9779c14ac..fa000c6f0 100644 --- a/server/middlewares/secure.js +++ b/server/middlewares/secure.js @@ -34,8 +34,13 @@ function decryptBody (req, res, next) { return res.sendStatus(500) } - req.body.data = JSON.parse(decrypted) - delete req.body.key + try { + req.body.data = JSON.parse(decrypted) + delete req.body.key + } catch (err) { + logger.error('Error in JSON.parse', { error: err }) + return res.sendStatus(500) + } next() }) -- cgit v1.2.3