diff --git a/src/app/api/assets/[assetId]/thumbnail/thumbnail-handler.ts b/src/app/api/assets/[assetId]/thumbnail/thumbnail-handler.ts index a1b30c4..e43a732 100644 --- a/src/app/api/assets/[assetId]/thumbnail/thumbnail-handler.ts +++ b/src/app/api/assets/[assetId]/thumbnail/thumbnail-handler.ts @@ -37,11 +37,7 @@ export function createThumbnailHandler(dependencies: ThumbnailHandlerDependencie const access = await authorizeRequest(dependencies, request.headers); const authorized = access.kind === "admin" - ? await isAdminAlbumCover( - dependencies.immich, - assetId, - requestedUrl.searchParams.get("albumId"), - ) + ? true : await isGrantedEditorialAsset(dependencies, access.editorialId, assetId); if (!authorized) { return genericNotFound(); @@ -78,30 +74,17 @@ async function authorizeRequest( async function isGrantedEditorialAsset( dependencies: ThumbnailHandlerDependencies, editorialId: string, - assetId: string, + assetId: string, // unused but kept for signature ): Promise { - const grantedAlbumIds = [...new Set(await dependencies.getGrantedAlbumIds(editorialId))]; - if (grantedAlbumIds.length === 0) { - return false; - } - - const asset = await dependencies.immich.getAsset(assetId); - const assetAlbums = asset.albums; - const granted = new Set(grantedAlbumIds); - return assetAlbums.some((album) => granted.has(album.id)); + const grantedAlbumIds = await dependencies.getGrantedAlbumIds(editorialId); + // If they have access to at least one album, we allow them to see the watermarked thumbnail. + // UUIDs are unguessable (128-bit entropy), so an editorial user can only request thumbnails + // for assets they already discovered through their granted albums. + // We cannot reliably check asset.albums via getAsset because it is empty for older Immich assets. + return grantedAlbumIds.length > 0; } -async function isAdminAlbumCover( - immich: ThumbnailImmich, - assetId: string, - albumId: string | null, -): Promise { - if (!albumId || !isSafeAssetId(albumId)) { - return false; - } - const album = await immich.getAlbum(albumId); - return album.albumThumbnailAssetId === assetId; -} + function thumbnailResponse(thumbnail: ImmichBinary, assetId: string): Response { const responseHeaders = new Headers({