Add library access checks on media progress endpoints

This commit is contained in:
advplyr committed 2026-11-09 17:10:22 -06:00
1 parent f88fdf1321
commit 83dce682e8
2 files changed
+34 -5

No files matched your search

+1 -1
View File
@@ -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) {
+33 -4
View File
@@ -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