From 92ea1480996c8566444c81e471ba23faf718088a Mon Sep 17 00:00:00 2001 From: Andy Bodnar Date: Sat, 10 Jan 2026 13:39:33 -0700 Subject: [PATCH] fix: validate share link before serving direct asset URLs Direct asset URLs (/share/photo/:key/:id and /share/video/:key/:id) were bypassing password protection. This fix: - Validates the share link via getShareByKey() before serving - Redirects to share page if password is required but not provided - Verifies the requested asset belongs to the share link Fixes #173 --- app/src/index.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/src/index.ts b/app/src/index.ts index 0305a7a..a5a2db8 100644 --- a/app/src/index.ts +++ b/app/src/index.ts @@ -125,6 +125,27 @@ app.get('/share/:type(photo|video)/:key/:id/:size?', decodeCookie, async (req, r return } + // Security fix: Validate share link and check password before serving assets + // This prevents direct URL access from bypassing password protection + const share = await immich.getShareByKey(req.params.key, req.password) + if (!share) { + respondToInvalidRequest(res, 404, 'Invalid share link') + return + } + + // If password is required but not provided, redirect to the share page + if (share.passwordRequired) { + res.redirect('/share/' + req.params.key) + return + } + + // Verify the requested asset belongs to this share link + const assetBelongsToShare = share.assets?.some(a => a.id === req.params.id) + if (!assetBelongsToShare) { + respondToInvalidRequest(res, 404, 'Asset not found in share') + return + } + const request = { req, key: req.params.key,