From b1d558b3fc1b99c0be297e0f61da0b4a077ececb Mon Sep 17 00:00:00 2001 From: Mayank Gautam Date: Mon, 17 Feb 2020 22:26:16 +0530 Subject: [PATCH 1/2] Added safegaurd against invalid project id in the method getFileContent --- server/controllers/file.controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/controllers/file.controller.js b/server/controllers/file.controller.js index 69625a18..f915f613 100644 --- a/server/controllers/file.controller.js +++ b/server/controllers/file.controller.js @@ -110,7 +110,7 @@ export function deleteFile(req, res) { export function getFileContent(req, res) { Project.findById(req.params.project_id, (err, project) => { - if (err) { + if (err || project == null) { res.status(404).send({ success: false, message: 'Project with that id does not exist.' }); return; } From bea3119147a413fbd5598b167ec8bad5ae0d6a88 Mon Sep 17 00:00:00 2001 From: Mayank Gautam Date: Tue, 18 Feb 2020 09:06:06 +0530 Subject: [PATCH 2/2] added undefined filePath check in the method resolvePathToFile --- server/utils/filePath.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/utils/filePath.js b/server/utils/filePath.js index 027b0e13..6a1ea673 100644 --- a/server/utils/filePath.js +++ b/server/utils/filePath.js @@ -1,4 +1,8 @@ export function resolvePathToFile(filePath, files) { + if (typeof filePath === 'undefined') { + return false; + } + const filePathArray = filePath.split('/'); let resolvedFile; let currentFile = files.find(file => file.name === 'root');