From 353642c870e569dfc251a5986a1586c8ce1b8450 Mon Sep 17 00:00:00 2001 From: Sheogorath Date: Wed, 26 Sep 2018 16:00:01 +0200 Subject: [PATCH 1/3] Fix document length limit on post We recently introduced a new way to create notes using a post requeest to the `/new` endpoint. This is not limited in size, other than pasting a note in the editor. This patch should enforce this limit also on this way. Signed-off-by: Sheogorath --- lib/response.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/response.js b/lib/response.js index 295f91d..8133b1a 100644 --- a/lib/response.js +++ b/lib/response.js @@ -32,6 +32,9 @@ var response = { errorBadRequest: function (res) { responseError(res, '400', 'Bad Request', 'something not right.') }, + errorTooLong: function (res) { + responseError(res, '413', 'Payload Too Large', 'Shorten your note!') + }, errorInternalError: function (res) { responseError(res, '500', 'Internal Error', 'wtf.') }, @@ -145,7 +148,12 @@ function responseCodiMD (res, note) { function newNote (req, res, next) { var owner = null - var body = req.body ? req.body : '' + var body = '' + if (req.body && req.body.length > config.documentMaxLength) { + return response.errorTooLong(res) + } else { + body = req.body + } body = body.replace(/[\r]/g, '') if (req.isAuthenticated()) { owner = req.user.id From 57e6d3a4820bfaa95ed99ede6542e2f2e404c791 Mon Sep 17 00:00:00 2001 From: Sheogorath Date: Tue, 25 Sep 2018 14:15:36 +0200 Subject: [PATCH 2/3] Set default to `v4` Seems like we didn't fix the problem with the last patch. This should finally fix it. Signed-off-by: Sheogorath --- lib/config/default.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/config/default.js b/lib/config/default.js index 6096bce..c34279b 100644 --- a/lib/config/default.js +++ b/lib/config/default.js @@ -104,7 +104,8 @@ module.exports = { baseURL: undefined, clientID: undefined, clientSecret: undefined, - scope: undefined + scope: undefined, + version: 'v4' }, mattermost: { baseURL: undefined, From c03b42d5d4f804d0cdbaf00c5eb426ca95f2a1cf Mon Sep 17 00:00:00 2001 From: Sheogorath Date: Fri, 28 Sep 2018 00:17:34 +0200 Subject: [PATCH 3/3] Fix little bug in length limit Signed-off-by: Sheogorath --- lib/response.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/response.js b/lib/response.js index 8133b1a..4df036b 100644 --- a/lib/response.js +++ b/lib/response.js @@ -151,7 +151,7 @@ function newNote (req, res, next) { var body = '' if (req.body && req.body.length > config.documentMaxLength) { return response.errorTooLong(res) - } else { + } else if (req.body) { body = req.body } body = body.replace(/[\r]/g, '')