fix(media): stop building unauthenticated public URLs for S3-compatible avatars/icons (#11865)

This commit is contained in:
Saim Hashmi
2026-10-16 00:18:36 +02:00
committed by GitHub
parent f5ead3ed43
commit d712afbc04
3 changed files with 21 additions and 7 deletions
+10 -3
View File
@@ -915,6 +915,15 @@ function s3_image_url(?int $storageId, ?string $path, int $version): ?string
return null;
}
// S3-compatible endpoints (e.g. Cloudflare R2) require authenticated requests for
// every object, including plain GETs, so an unauthenticated direct link only works
// when a public CDN has been configured in front of the bucket. Without one, callers
// must fall back to the app's own authenticated proxy route.
$cdnUrl = instanceSettings()->image_cdn_url;
if (blank($cdnUrl)) {
return null;
}
$storage = S3Storage::query()
->whereKey($storageId)
->whereTeamId(0)
@@ -925,9 +934,7 @@ function s3_image_url(?int $storageId, ?string $path, int $version): ?string
return null;
}
$baseUrl = instanceSettings()->image_cdn_url ?: $storage->awsUrl();
return rtrim($baseUrl, '/').'/'.ltrim($path, '/').'?v='.$version;
return rtrim($cdnUrl, '/').'/'.ltrim($path, '/').'?v='.$version;
}
/**