Supabase Storage access control stops at the CDN cache

Supabase Storage access control is the set of Postgres Row Level Security policies on the storage.objects table that decides who can upload, list, read and delete each file. It decides when a request reaches Storage. Once a response sits in the CDN cache, nobody asks the policy again, and that is where a private file can outlive the permission that let someone open it.
This matters to any product that keeps files people expect to stay private: signed contracts, invoices, ID scans, medical letters, exports. One search that reaches us reads, word for word: can Supabase Storage meet GDPR and per-file access controls compared to S3 plus a CDN, for millions of users? It can. The rules are stricter than the defaults suggest, and four of them live outside the policy.
How does Supabase Storage decide who can read a file?
Every file is a row in storage.objects, with its bucket, its path in name and the user who uploaded it in owner_id. Storage turns each API call into a query on that table, so a policy works on files the way it works on any other table. With no policy, nothing goes through: Supabase's access control guide states that Storage allows no uploads to a bucket until a policy grants them.
Three tools do most of the work:
- The path.
storage.foldername(name)returns the folders a file sits in, as an array. Put the workspace or user id first in every path and a policy can match on(storage.foldername(name))[1]. - The owner.
owner_idcomes from thesubclaim of the uploader's JWT. A file created with the service key, or from the dashboard, has no owner, as the ownership docs note, so an owner-only policy never matches it. - The operation. Listing a folder and downloading a file both need
SELECT.storage.allow_only_operation()andstorage.allow_any_operation()let a policy open downloads and signing and keep listing shut.
Here is a policy for a B2B product where every file belongs to a workspace:
create policy "members read their workspace files"
on storage.objects for select
to authenticated
using (
bucket_id = 'documents'
and storage.allow_any_operation(array['object.get_authenticated', 'object.sign'])
and (storage.foldername(name))[1] in (
select workspace_id::text
from public.memberships
where user_id = (select auth.uid())
)
);Two details in it carry the performance. auth.uid() sits inside a select, so Postgres runs it once per statement instead of once per row, and memberships.user_id needs an index of its own. Supabase's RLS performance guide shows a policy on an unindexed column scanning 100,000 rows in 171 ms for a query that returned nothing. On a bucket with millions of objects, that cost lands on every list and every download. The patterns that keep policies fast are in Supabase RLS at scale.
Folders are only key prefixes. Storage has no folder permissions that the files inside inherit, and Supabase's own troubleshooting note recommends modelling the hierarchy in a table of your own, joined from the policy and indexed. Shared folders, nested projects and per-document sharing all belong there.
Where does Supabase Storage access control stop?
Private files reach a browser in two ways: a signed URL, or a request to the authenticated endpoint carrying the user's JWT. On the Pro plan and above, the Smart CDN caches both, and the Smart CDN documentation is precise about what it does with them. Four facts follow.
- An expired token does not stop a cached response. Each signed URL is its own cache key. Once a response is cached at the edge, the same URL keeps being served until the CDN cache duration ends, even after the token inside it has expired. Revoking or expiring a token does not purge its entry.
- A single signed URL cannot be revoked. The serving guide lists the options: delete, move or rename the object. Rotating the project's URL signing key revokes every signed URL at once, and the signing keys page adds that copies already cached can still be served until the cache is purged.
- The cache does not see a policy change. On the authenticated endpoint, the CDN caches each response on the access the user had when they asked, and serves it until their JWT expires. Remove someone from a workspace and the files they opened stay reachable until you purge the cache or the token runs out.
- Signing out ends the session, not the token. An access token already issued stays valid until it expires. The same holds when a user is deleted: the user management docs state that deleting a user does not sign them out.
Under all four sits the browser cache. A CDN purge leaves it alone, and a file stays there until its cacheControl runs out. Supabase calls one hour a reasonable default.
None of this is a defect. A CDN that asked Postgres before every hit would not be a cache. The work is to decide, file type by file type, how long a person may keep access after you take it away, and then set the numbers to match.
How do you close each gap?
Sort files by how fast access must end
Private files fall into two groups. Avatars, logos and product photos are private because they belong to someone, and nobody is harmed if a former teammate sees one for another hour. Contracts, payslips and health records are different: access has to end when the permission ends. The first group can live in a public bucket or behind long signed URLs. The second gets the rules below. The Smart CDN guide itself advises a public bucket when an asset has no meaningful per-user restriction, since it caches better and needs no signing.
Reuse short signed URLs within a page view
A signed URL generated on every request never warms the cache, so every view goes to the origin. One generated when the page opens, and reused while it stays open, caches well. For sensitive files we sign for minutes, not days, and set a short cacheControl at upload, which bounds the browser. The CDN copy is bounded by one thing only: the object itself. That is the next rule.
Revoke by moving the file
When access to a sensitive file has to end now, we move it to a new path. Supabase invalidates every cached entry for an object when it changes, across all tokens, within 60 seconds. Paths that end in a version, like ws_42/contracts/981/v3.pdf, make this routine: the move is a new version, the old URLs stop working, and the database row points at the new path.
Purge when a permission changes
Removing a member, changing a role or editing a policy should call the purge API for the files that member could reach. It needs the secret key, so it runs on the server. It takes an exact path or a whole bucket, with no wildcards, as the purge documentation explains, and it is a Pro plan feature. A bucket-wide purge costs every customer a cold cache, so we keep sensitive files in a bucket of their own.
Shorten the access token
The authenticated endpoint trusts the JWT until it expires, so the token's lifetime is your revocation delay. You lower it in the project's session settings; new tokens get the new expiry and existing ones keep theirs. On products that hold documents we set it in minutes and accept the extra refresh calls.
Put a server in front of the files that cannot wait
For files where even a minute is too long, the check moves into your own code. An Edge Function or a route handler verifies the session and the permission on every request, then fetches the file from Storage with the secret key and streams it back. Supabase documents this as the way to revoke access immediately. The CDN still caches between Storage and your server, and what the user receives is decided by your code, request by request. Mark those responses private, no-store so no shared cache keeps them.
Can Supabase Storage meet GDPR for millions of users?
It can carry a compliant setup. Supabase's GDPR page describes a shared responsibility: Supabase secures the infrastructure and offers a Data Processing Agreement, and you own the processing, the consent and the access rules. On the storage side, four points decide whether it holds up.
- Region. A project lives in one primary region, and its database, Auth and Storage objects stay there. The general "Europe" grouping includes London and Zurich, which are not EU member states, so pick a specific EU region if your contracts say EU. Backups, logs, Edge Functions and sub-processors still belong in your transfer analysis.
- Erasure. Delete files through the Storage API, never with SQL on
storage.objects: the delete guide warns that a SQL delete leaves the file orphaned in the bucket.remove()takes 1,000 paths per call, and emptying a bucket through the API stops at 200,000 objects. Past that, Supabase points to its S3 protocol. - Account deletion order. Supabase refuses to delete an Auth user who still owns Storage objects. Files first, then the user. Deleting the objects also clears their CDN entries, within a minute.
- Who opened what. A breach investigation asks who opened which file. Policies decide access but keep no record of it. Files served through your own server, as above, give you that record.
Against S3 behind CloudFront, the trade is plain. S3 has IAM, bucket policies and more regions, and its Signature Version 4 presigned URLs last at most seven days. Supabase keeps the access rule in SQL, next to the memberships it depends on, which a small team keeps right more easily than an IAM policy synced to an app database. The cache questions are the same on both: a CDN in front of private files always needs a revocation plan. For cost and egress, see Cloudflare R2 vs S3 vs Supabase Storage. For strict residency customer by customer, see a bucket per tenant on R2.
GDPR obligations depend on your processing, your contracts and your sector. A data protection officer or a lawyer should sign off on the design. This article describes how the storage mechanics behave, not what the law requires of you.
What this looks like in practice
Take a contract tool where each workspace stores signed PDFs. This is the setup we would ship:
- One private bucket,
documents, with paths shaped{workspace_id}/{document_id}/v{n}.pdf. - One
SELECTpolicy joined to an indexedmembershipstable and limited to downloads and signing, with no listing policy: the app lists documents from its own table. - Signed URLs of five minutes, created when a document page opens and reused while it stays open, with a short
cacheControl. - On member removal, a background job that purges the workspace's document paths, read from the documents table. The five-minute URLs bound what is left.
- On "withdraw this document", the file moves to
v{n+1}and every old URL stops within a minute. - On account erasure, files removed through the API in batches of 1,000, then the Auth user, then the rows.
Payroll or medical files would add the server route on top, so every download is checked and logged.
Sources
- Storage Access Control, Supabase Docs
- Storage Ownership, Supabase Docs
- Row Level Security Performance, Supabase Docs
- Storage: folder operations and hierarchical RLS, Supabase Docs
- Smart CDN, Supabase Docs
- Serving assets from Storage, Supabase Docs
- URL signing keys, Supabase Docs
- Purge CDN Cache, Supabase Docs
- User Management, Supabase Docs
- GDPR compliance and Supabase, Supabase Docs
- Delete Objects, Supabase Docs
- Authenticating Requests: Using Query Parameters (AWS Signature Version 4), Amazon S3
Frequently asked questions
Not for anything sensitive. Anyone holding the URL can read a file in a public bucket, and a random name is a secret that leaks through shared links, browser history, server logs and screenshots. There is also no way to take access back except moving or deleting the file. Random names are fine for assets nobody would mind seeing in the wrong hands, such as product photos. Contracts, ID documents and health records belong in a private bucket behind policies.
As long as the screen that uses it, which usually means minutes. Sign the URL when the page opens and reuse it while the page stays open, so the CDN can cache it. Expiry alone does not end access: a cached response for that exact URL can still be served after the token has expired. To end access to a file now, move or delete it, which invalidates every cached copy within about a minute.
Yes. Your server calls Storage with the secret key, which bypasses RLS, so for those downloads your own code is the real check. A deny-by-default set of policies still protects the bucket from the publishable key that ships in your client, from an upload path someone forgot, and from a future feature that talks to Storage directly. On the server route it costs nothing, because the secret key skips the policies.
No. Supabase refuses to delete an Auth user who still owns Storage objects, so the files have to go first, through the Storage API, in batches of up to 1,000 paths. Deleting rows from storage.objects with SQL leaves the files orphaned in the bucket instead of removing them. Deleting the user does not sign them out either: their access token stays valid until it expires, which is one more reason to keep that lifetime short.
Related articles
May 22, 2026 · 7 min read
May 28, 2026 · 10 min read
May 9, 2026 · 9 min read