Skip to content

Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.

fix: address remaining PR review findings for protected albums

copilot-swe-agent[bot]0d6cc1ff077f
diff --git a/app/components/photo/ShareModal.vue b/app/components/photo/ShareModal.vue
index 377bc1ca..edfab32e 100644
--- a/app/components/photo/ShareModal.vue
+++ b/app/components/photo/ShareModal.vue
@@ -262,7 +262,19 @@ const downloadOriginalImage = async () => {
const url = window.URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
- const extension = props.photo.originalUrl!.split('.').pop() || 'jpg'
+ const mimeType = blob.type.toLowerCase()
+ const extensionByMime: Record<string, string> = {
+ 'image/jpeg': 'jpg',
+ 'image/png': 'png',
+ 'image/webp': 'webp',
+ 'image/gif': 'gif',
+ 'image/avif': 'avif',
+ 'image/heic': 'heic',
+ 'image/heif': 'heif',
+ 'image/bmp': 'bmp',
+ 'image/tiff': 'tiff',
+ }
+ const extension = extensionByMime[mimeType] || props.photo.originalUrl!.split('.').pop() || 'jpg'
link.download = `${props.photo.title || 'photo'}.${extension}`
document.body.appendChild(link)
link.click()
diff --git a/server/api/albums/[albumId]/unlock.post.ts b/server/api/albums/[albumId]/unlock.post.ts
index 22aa744b..8f33471e 100644
--- a/server/api/albums/[albumId]/unlock.post.ts
+++ b/server/api/albums/[albumId]/unlock.post.ts
@@ -5,14 +5,25 @@ import { grantAlbumAccess, verifyAlbumPassword } from '../../../utils/album-acce
const UNLOCK_WINDOW_MS = 60_000
const UNLOCK_MAX_ATTEMPTS = 8
+const UNLOCK_MAX_ENTRIES = 5_000
const unlockAttempts = new Map<string, { count: number; resetAt: number }>()
+function pruneUnlockAttempts(now: number) {
+ for (const [key, attempt] of unlockAttempts) {
+ if (attempt.resetAt <= now) unlockAttempts.delete(key)
+ }
+}
+
function assertUnlockRateLimit(event: H3Event, albumId: number) {
- const ip = getRequestIP(event, { xForwardedFor: true }) || 'unknown'
+ const ip = getRequestIP(event, { xForwardedFor: false }) || 'unknown'
const now = Date.now()
+ pruneUnlockAttempts(now)
const key = `${albumId}:${ip}`
const attempt = unlockAttempts.get(key)
if (!attempt || attempt.resetAt <= now) {
+ if (unlockAttempts.size >= UNLOCK_MAX_ENTRIES) {
+ unlockAttempts.delete(unlockAttempts.keys().next().value as string)
+ }
unlockAttempts.set(key, { count: 1, resetAt: now + UNLOCK_WINDOW_MS })
return
}
@@ -27,13 +38,13 @@ export default eventHandler(async (event) => {
z.object({ albumId: z.coerce.number().int().positive() }).parse)
const { password } = await readValidatedBody(event,
z.object({ password: z.string().min(1).max(128) }).parse)
- const clientIp = getRequestIP(event, { xForwardedFor: true }) || 'unknown'
- assertUnlockRateLimit(event, albumId)
+ const clientIp = getRequestIP(event, { xForwardedFor: false }) || 'unknown'
const album = useDB().select().from(tables.albums)
.where(eq(tables.albums.id, albumId)).get()
if (!album || album.isHidden || !album.passwordHash) {
throw createError({ statusCode: 404, statusMessage: 'Album not found' })
}
+ assertUnlockRateLimit(event, albumId)
if (!await verifyAlbumPassword(password, album.passwordHash)) {
throw createError({ statusCode: 401, statusMessage: 'Incorrect album password' })
}
diff --git a/server/routes/thumb/[...thumbnailUrl].get.ts b/server/routes/thumb/[...thumbnailUrl].get.ts
index d0ce17a1..e100dc88 100644
--- a/server/routes/thumb/[...thumbnailUrl].get.ts
+++ b/server/routes/thumb/[...thumbnailUrl].get.ts
@@ -14,17 +14,22 @@ export default eventHandler(async (event) => {
}
url = decodeURIComponent(url)
- const restricted = await assertPhotoAccess(event, url.startsWith('/storage/') || url.startsWith('/image/')
- ? url.replace(/^\/(?:storage|image)\//, '') : url)
+ const protectedPhotoMatch = /^\/image\/__photo__\/([^/]+)\/(?:thumbnail|original|live)$/.exec(url)
+ const accessKey = protectedPhotoMatch
+ ? decodeURIComponent(protectedPhotoMatch[1] || '')
+ : (url.startsWith('/storage/') || url.startsWith('/image/')
+ ? url.replace(/^\/(?:storage|image)\//, '')
+ : url)
+ const restricted = await assertPhotoAccess(event, accessKey)
if (restricted) setHeader(event, 'Cache-Control', 'private, no-store')
const shouldForwardCookieToStorage =
storageProvider.config?.provider === 'local' &&
- url.startsWith('/storage/')
+ (url.startsWith('/storage/') || url.startsWith('/image/'))
if (
storageProvider.config?.provider === 'local' &&
- url.startsWith('/storage/')
+ (url.startsWith('/storage/') || url.startsWith('/image/'))
) {
const scheme = event.node.req.headers['x-forwarded-proto'] || 'http'
url = `${scheme}://${event.node.req.headers.host}${url}`