I've set up my Firestore rules like this:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
///Rules:
///Only the owner can modify their stuff under the Users collection
match /users/{uid} {
allow read, write, delete: if isOwner(uid) && emailVerified();
}
match /users/{uid}/groups/{groupID} {
allow read, write, delete: if isOwner(uid) && emailVerified();
}
match /users/{uid}/friends/{friendID} {
allow read, write, delete: if isOwner(uid) && emailVerified();
}
match /users/{uid}/notifications/{notifID} {
allow read, write, delete: if isOwner(uid) && emailVerified();
}
/// Functions ///
function emailVerified() {
return request.auth.token.email_verified; ///returns true if email is verified
}
function isOwner(uid) {
return request.auth.uid == uid
}
}
}
Basically, the idea is this: a user can only modify records in the sub-collections within their user document. The sub-collections are groups, friends, and notifications. The rules will check the incoming request.auth.uid
and see if it matches the uid
in users/{uid}
before allowing them to modify any sub-collection.
I'm just now realizing that within the friends
collection I'm storing the uid
of those friends. So now I'm worried that there might be a security risk. If a user downloads their friends list, they will receive the uid
of those friends. Could a malicious user then use the uid
to impersonate that friend and modify their firestore records?