Firestore Security Rules breaking with update rule

穿精又带淫゛_ 提交于 2019-12-20 04:34:12

问题


I posted a question about this yesterday but I'm creating a new one with more details. Firestore .setData is blocked by update rule not create

I've run the simulator and the rules work there. Also when I create the document and change setData in the swift code to update the code works. It appears to only fail when creating the document. But the catch is that when I remove the update rule or simply change it to allow update: if false; the setData (or seen as create by the rules) executes properly. I have no clue whats going on nor do I know of any tools for getting a better insight.

 match /users_real/{userID} {
    allow create: if true;
    allow read: if isOwner(userID);
    allow update: if (request.writeFields.size() == 1);

}

set data:

self.docRef.collection("users_real").document("adfadsf").setData(post) { (error) in

            if let error = error {
                print("He dead!: \(error.localizedDescription)")


            }
            else {
                print("it worked, for now")


            }
        }

回答1:


Firebase Support confirms that there is a bug related to the evaluation of request.writeFields.size(). No estimate was given of when it will be fixed.

The existence of the bug can be demonstrated with the following rules:

service cloud.firestore {
  match /databases/{database}/documents {

    match /cities/{city} {
      // This should always evaluate to true, but does not.
      allow create: if (request.writeFields.size() == 1) || (request.writeFields.size() != 1);
      allow update: if true;
    }
  }
}

Although the create rule should always evaluate to true, an attempt to create a city fails with Permission Denied. It seems that the problem with request.writeFields affects not only the rule in which it appears, but also other rules for the path. For the rules shown above, an attempt to update an existing city also fails with Permission Denied.



来源:https://stackoverflow.com/questions/51633681/firestore-security-rules-breaking-with-update-rule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!