fix(#348): remove broad allow write from leaderboard Firestore rule#387
Merged
Aditya948351 merged 1 commit intoMay 31, 2026
Conversation
…derboard Firestore rule
The leaderboard/{userId} rule had both an allow write and an allow update
clause. Firestore evaluates allow statements with OR logic, so the broader
allow write was always matched first for document owners. This rendered the
field-restricted allow update completely unreachable, letting any
authenticated user overwrite their own points with an arbitrary value.
Changes:
- Removed the allow write clause entirely.
- Added allow create, delete: if isSuperAdmin() so only the trusted
backend can provision or remove leaderboard entries.
- Kept allow update scoped to the document owner with an affectedKeys
check restricting writes to the points field only.
Fixes devpathindcommunity-india#348
Aditya948351
approved these changes
May 31, 2026
Collaborator
Aditya948351
left a comment
There was a problem hiding this comment.
Removing the broad allow write on the leaderboard is a massive security improvement. Thanks for spotting and fixing this Firestore rule!
Collaborator
|
Do star the repo! Successfully merging this and loved the changes you did. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #348
The
leaderboard/{userId}Firestore security rule had both anallow writeand a field-restrictedallow updateclause. Firestore evaluatesallowstatements with OR logic, so the broaderallow writealways matched first for document owners, makingallow updatecompletely unreachable. This let any authenticated user write arbitrary values to their ownpointsfield directly via the Firestore client SDK.Root cause
Fix
Changes
firestore.rules: removed theallow writeclause fromleaderboard/{userId}and replaced it with explicitallow create, delete: if isSuperAdmin().Security impact
db.doc('leaderboard/<uid>').set({ points: 99999 })and succeed.pointsfield only; create and delete operations require superadmin privileges.Test plan
pointsvalue via the Firestore client SDK and confirm it is rejected.