From 184858efaec9593376168e6527157af0664cf957 Mon Sep 17 00:00:00 2001 From: Nicholas Wallace Date: Sat, 31 Aug 2024 21:45:14 -0700 Subject: [PATCH] Ensure folder exists in library --- server/controllers/MiscController.js | 3 ++- server/controllers/PodcastController.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/server/controllers/MiscController.js b/server/controllers/MiscController.js index 97472b82b..be8ef60c0 100644 --- a/server/controllers/MiscController.js +++ b/server/controllers/MiscController.js @@ -49,7 +49,8 @@ class MiscController { return res.status(404).send(`Library not found with id ${libraryId}`) } const folder = await Database.libraryFolderModel.findByPk(folderId) - if (!folder) { + // Verify the folder matches the library ID so we don't accidentally add a podcast to the wrong path + if (!folder || folder.libraryId !== library.id) { return res.status(404).send(`Folder not found with id ${folderId} in library ${library.name}`) } diff --git a/server/controllers/PodcastController.js b/server/controllers/PodcastController.js index 977c4fec2..1e2f42903 100644 --- a/server/controllers/PodcastController.js +++ b/server/controllers/PodcastController.js @@ -45,7 +45,8 @@ class PodcastController { } const folder = await Database.libraryFolderModel.findByPk(payload.folderId) - if (!folder) { + // Verify the folder matches the library ID so we don't accidentally add a podcast to the wrong path + if (!folder || folder.libraryId !== library.id) { Logger.error(`[PodcastController] Create: Folder not found "${payload.folderId}"`) return res.status(404).send('Folder not found') }