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(ui): reject requests from obsolete Site and account scopes

HoshinoSuzumiBot408f96f6e512
diff --git a/packages/gallery/README.md b/packages/gallery/README.md
index 93b7aa7c..26e45330 100644
--- a/packages/gallery/README.md
+++ b/packages/gallery/README.md
@@ -14,5 +14,6 @@ Entry middleware installs a request-local `EntrySiteContext` before rendering.
Shared API helpers derive portal/public paths from that context and frame async
cache keys with its Site/audience/principal scope. Site/account changes clear
settings and viewer state; late settings responses cannot repopulate the old scope.
+API instances reject calls after their creating Site/account scope changes.
Self-hosted uses its existing unprefixed APIs when no platform context is installed.
Public capability flags describe available UI features, not authorization.
diff --git a/packages/gallery/app/composables/useEntryApi.ts b/packages/gallery/app/composables/useEntryApi.ts
index 7fc63d58..c1beccfe 100644
--- a/packages/gallery/app/composables/useEntryApi.ts
+++ b/packages/gallery/app/composables/useEntryApi.ts
@@ -1,10 +1,12 @@
import { useEntryContext, entryRequestPath } from './useEntryContext'
-/** Snapshot the context for this request; a route switch cannot retarget an in-flight request. */
+/** Bind to the creating scope; delayed handlers must never target a different Site/account. */
export function useEntryApi(baseURL: string) {
const context = useEntryContext()
const fetcher = useRequestFetch() as typeof $fetch
- return ((request: string, options?: Record<string, unknown>) => {
- const snapshot = context.value
+ const snapshot = context.value
+ return (async (request: string, options?: Record<string, unknown>) => {
+ if (context.value?.scope !== snapshot?.scope)
+ throw new Error('Site context changed; discard the previous request')
return fetcher(entryRequestPath(request, snapshot), { ...options, baseURL })
}) as typeof $fetch
}
diff --git a/tests/ui-api.test.ts b/tests/ui-api.test.ts
index 77eb54cf..83e015b9 100644
--- a/tests/ui-api.test.ts
+++ b/tests/ui-api.test.ts
@@ -92,6 +92,10 @@ for (const name of ['console', 'gallery'])
context.value = { ...context.value, scope: 'site:2:portal:user2' }
await api[`use${title}Fetch`]('/api/albums', { key: 'albums' })
assert.ok(String(calls.at(-1)!.options.key).includes('user2'))
- await fetcher('/api/photos', { baseURL: 'https://untrusted.example' })
+ await assert.rejects(fetcher('/api/photos'), /Site context changed/)
+ const currentFetcher = api[`use${title}Api`]()
+ await currentFetcher('/api/photos', {
+ baseURL: 'https://untrusted.example',
+ })
assert.equal(calls.at(-1)!.options.baseURL, '')
})