Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions firestore.rules
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,20 @@ service cloud.firestore {
}

// Leaderboard collection
// The broad allow write clause has been removed. It was evaluated first by
// Firestore's OR logic, making the field-restricted allow update below it
// completely unreachable, and letting any owner set arbitrary point values.
match /leaderboard/{userId} {
allow read: if true;
allow write: if (request.auth != null && request.auth.uid == userId) || isSuperAdmin(); // Owner or Super Admin can write
allow update: if request.auth != null && request.auth.uid == userId && (
(request.resource.data.diff(resource.data).affectedKeys().hasOnly(['points']))
);

// Only a superadmin (backend / Admin SDK) may create or delete entries.
allow create, delete: if isSuperAdmin();

// Owners may only touch the 'points' field. All other leaderboard
// mutations must go through the trusted backend.
allow update: if request.auth != null
&& request.auth.uid == userId
&& request.resource.data.diff(resource.data).affectedKeys().hasOnly(['points']);
}

// Resources collection
Expand Down