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
This commit is contained in:
Andy Bodnar
2026-01-10 13:39:33 -07:00
parent d67a21074d
commit 92ea148099
+21
View File
@@ -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,