Lock Down Firestore Profile Updates with Field AllowlistingLock Down Firestore Profile Updates with Field Allowlisting
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started
If signed-in users can update their own profile in Firestore, check whether they can also change their own role.
A rule that only asks "is this your document?" lets the owner write any field in it. If a role or a quiz score lives there, that is a way in.
Firebase's docs show a fix: compare the new document with the stored one using request.resource.data.diff(resource.data).affectedKeys(), then allow only a named list with hasOnly(['name', 'photoUrl']). An allow list beats blocking specific fields, because new fields stay locked until you add them.
Then prove it in the Local Emulator: sign in as a normal user, try to write role: 'admin', and expect a denial.
Ahmar's avatar
That is such a common Firestore pitfall. Checking affectedKeys() on updates saves a lot of headaches before anything goes to production.
Ecom Swift's avatar
Agreed. Worth checking create too, not just update. If a user can delete their profile doc and write it again with a higher role, the update rule never runs.
Back to feed
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started