fix: include project ID in storage preview cache key

Cache key never included the project ID, so two projects with the same
bucketId, fileId, and transform params would share a cache key. On a
cache hit, Appwrite re-validates the bucket from the cached resourceType
(another project's bucket), which doesn't exist in the requesting
project's DB, throwing storage_bucket_not_found.

Fix: add 'project' to cache.params on the preview route (covers query
param case) and fall back to the X-Appwrite-Project header in
cacheIdentifier() for authenticated requests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
loks0n
2026-04-17 18:34:13 +01:00
parent 956285d522
commit ad3bdee6c1
2 changed files with 4 additions and 1 deletions
@@ -54,7 +54,7 @@ class Get extends Action
->label('cache', true)
->label('cache.resourceType', 'bucket/{request.bucketId}')
->label('cache.resource', 'file/{request.fileId}')
->label('cache.params', ['width', 'height', 'gravity', 'quality', 'borderWidth', 'borderColor', 'borderRadius', 'opacity', 'rotation', 'background', 'output'])
->label('cache.params', ['width', 'height', 'gravity', 'quality', 'borderWidth', 'borderColor', 'borderRadius', 'opacity', 'rotation', 'background', 'output', 'project'])
->label('sdk', new Method(
namespace: 'storage',
group: 'files',
+3
View File
@@ -239,6 +239,9 @@ class Request extends UtopiaRequest
$params = array_intersect_key($params, array_flip($allowedParams));
}
ksort($params);
if (!isset($params['project'])) {
$params['project'] = $this->getHeader('x-appwrite-project', '');
}
return md5($this->getURI() . '*' . serialize($params) . '*' . APP_CACHE_BUSTER);
}