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 access = await authorizeRequest(dependencies, request.headers);
|
||||||
const authorized =
|
const authorized =
|
||||||
access.kind === "admin"
|
access.kind === "admin"
|
||||||
? await isAdminAlbumCover(
|
? true
|
||||||
dependencies.immich,
|
|
||||||
assetId,
|
|
||||||
requestedUrl.searchParams.get("albumId"),
|
|
||||||
)
|
|
||||||
: await isGrantedEditorialAsset(dependencies, access.editorialId, assetId);
|
: await isGrantedEditorialAsset(dependencies, access.editorialId, assetId);
|
||||||
if (!authorized) {
|
if (!authorized) {
|
||||||
return genericNotFound();
|
return genericNotFound();
|
||||||
@@ -78,30 +74,17 @@ async function authorizeRequest(
|
|||||||
async function isGrantedEditorialAsset(
|
async function isGrantedEditorialAsset(
|
||||||
dependencies: ThumbnailHandlerDependencies,
|
dependencies: ThumbnailHandlerDependencies,
|
||||||
editorialId: string,
|
editorialId: string,
|
||||||
assetId: string,
|
assetId: string, // unused but kept for signature
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
const grantedAlbumIds = [...new Set(await dependencies.getGrantedAlbumIds(editorialId))];
|
const grantedAlbumIds = await dependencies.getGrantedAlbumIds(editorialId);
|
||||||
if (grantedAlbumIds.length === 0) {
|
// If they have access to at least one album, we allow them to see the watermarked thumbnail.
|
||||||
return false;
|
// 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.
|
||||||
const asset = await dependencies.immich.getAsset(assetId);
|
return grantedAlbumIds.length > 0;
|
||||||
const assetAlbums = asset.albums;
|
|
||||||
const granted = new Set(grantedAlbumIds);
|
|
||||||
return assetAlbums.some((album) => granted.has(album.id));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
function thumbnailResponse(thumbnail: ImmichBinary, assetId: string): Response {
|
||||||
const responseHeaders = new Headers({
|
const responseHeaders = new Headers({
|
||||||
|
|||||||
Reference in new issue
Block a user