fix: bypass broken asset.albums authorization check for thumbnails
This commit is contained in:
1 parent
ed957e6559
commit
986828893b
1 file changed
+9
-26
@@ -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<boolean> {
|
||||
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<boolean> {
|
||||
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({
|
||||
|
||||
Reference in new issue
Block a user