From 83dce682e88c2b32b0c33a8f83a9457bfc459e0e Mon Sep 17 00:00:00 2001 From: advplyr Date: Mon, 9 Nov 2026 17:10:22 -0600 Subject: [PATCH] Add library access checks on media progress endpoints --- server/controllers/MeController.js | 2 +- server/models/User.js | 37 ++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/server/controllers/MeController.js b/server/controllers/MeController.js index ca600d373..03841b5ca 100644 --- a/server/controllers/MeController.js +++ b/server/controllers/MeController.js @@ -495,7 +495,7 @@ class MeController { for (const mediaProgress of mediaProgressesInProgress) { const oldMediaProgress = mediaProgress.getOldMediaProgress() const libraryItem = libraryItems.find((li) => li.id === oldMediaProgress.libraryItemId) - if (libraryItem) { + if (libraryItem && req.user.checkCanAccessLibraryItem(libraryItem)) { if (oldMediaProgress.episodeId && libraryItem.isPodcast) { const episode = libraryItem.media.podcastEpisodes.find((ep) => ep.id === oldMediaProgress.episodeId) if (episode) { diff --git a/server/models/User.js b/server/models/User.js index 9ad4772d5..e445f658a 100644 --- a/server/models/User.js +++ b/server/models/User.js @@ -743,10 +743,10 @@ class User extends Model { }, { model: this.sequelize.models.podcast, - attributes: ['id', 'title'], + attributes: ['id', 'title', 'explicit', 'tags'], include: { model: this.sequelize.models.libraryItem, - attributes: ['id'] + attributes: ['id', 'libraryId', 'mediaType'] } } ] @@ -758,15 +758,38 @@ class User extends Model { statusCode: 404 } } + const episodeLibraryItem = podcastEpisode.podcast?.libraryItem + if (!episodeLibraryItem) { + Logger.error(`[User] createUpdateMediaProgress: library item for episode ${progressPayload.episodeId} not found`) + return { + error: 'Library item not found', + statusCode: 404 + } + } + if (progressPayload.libraryItemId && episodeLibraryItem.id !== progressPayload.libraryItemId) { + Logger.error(`[User] createUpdateMediaProgress: episode ${progressPayload.episodeId} does not belong to library item ${progressPayload.libraryItemId}`) + return { + error: 'Episode does not belong to library item', + statusCode: 400 + } + } + episodeLibraryItem.media = podcastEpisode.podcast + if (!this.checkCanAccessLibraryItem(episodeLibraryItem)) { + Logger.error(`[User] createUpdateMediaProgress: user "${this.username}" attempted to update progress for inaccessible library item "${episodeLibraryItem.id}"`) + return { + error: 'User does not have access to this library item', + statusCode: 403 + } + } mediaItemId = podcastEpisode.id mediaProgress = podcastEpisode.mediaProgresses?.[0] podcastId = podcastEpisode.podcastId } else { const libraryItem = await this.sequelize.models.libraryItem.findByPk(progressPayload.libraryItemId, { - attributes: ['id', 'mediaId', 'mediaType'], + attributes: ['id', 'libraryId', 'mediaId', 'mediaType'], include: { model: this.sequelize.models.book, - attributes: ['id', 'title'], + attributes: ['id', 'title', 'explicit', 'tags'], required: false, include: { model: this.sequelize.models.mediaProgress, @@ -787,6 +810,12 @@ class User extends Model { error: 'Library item is not a book', statusCode: 400 } + } else if (!this.checkCanAccessLibraryItem(libraryItem)) { + Logger.error(`[User] createUpdateMediaProgress: user "${this.username}" attempted to update progress for inaccessible library item "${libraryItem.id}"`) + return { + error: 'User does not have access to this library item', + statusCode: 403 + } } mediaItemId = libraryItem.media.id