Skip to content

All Firestore writes prevented by 2x"Missing or insufficient permissions" in quick succession #835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Ruberik opened this issue Feb 22, 2018 · 3 comments
Assignees

Comments

@Ruberik
Copy link

Ruberik commented Feb 22, 2018

  • Xcode version: 9.2
  • Firebase SDK version: 4.9.0 (also appears to be a problem for 4.8.0)
  • Firebase Component: Firestore
  • Component version: 0.10.1 (also appears to be a problem for 0.9.4)

Steps to reproduce:

When multiple "Missing or insufficient permissions" errors occur in quick succession, the client stops successfully writing to Firestore, and apparently stops trying to.

I'll provide specific code later, but the outline is:

  1. Set up rules with a collection that can't be written to, foo, and a collection that can be written to, bar.
  2. Write something to "bar" to confirm you can.
  3. In a loop, write something to "foo" three times.
  4. Confirm you can no longer write to "bar", or even get a callback with an error from attempting to write to "foo".

Relevant Code:

Firestore rules:

service cloud.firestore {
  match /databases/{database}/documents {
    match /bar/{id} {
      allow read, write: if true;
    }
    match /foo/{id} {
      allow read, write: if false;
    }
  }
}

Code:

  1. Take quickstart-ios's firestore "FriendlyEats" quickstart.
  2. Replace the following two functions in RestaurantsTableViewController as follows:
  @IBAction func didTapPopulateButton(_ sender: Any) {
    NSLog("Populate tapped")
    let uid = Auth.auth().currentUser!.uid
    Firestore.firestore().collection("bar").document().setData(["a": 5]) {
      NSLog("bar result: \($0)")
    }
  }

  @IBAction func didTapFilterButton(_ sender: Any) {
    NSLog("Filter button tapped")
    for _ in [1, 2, 3] {
      Firestore.firestore().collection("foo").document().setData(["a": 5]) {
        NSLog("foo result: \($0?.localizedDescription)")
      }
    }
  }
  1. In AppDelegate, optionally add some or all of:
    Firestore.enableLogging(true)
    let settings = FirestoreSettings()
    settings.isPersistenceEnabled = false
    Firestore.firestore().settings = settings

This bug appears to be independent of whether offline persistence is enabled.

  1. Start the app, and log in.

  2. Click "populate" and check your database to confirm that something was written in the "bar" collection.

  3. Click "filter" and confirm that you get a bunch of "Missing or insufficient permissions" errors.

  4. Click "populate" and "filter" and confirm that you don't get any more callbacks or any database writes; just "X button tapped" log messages.

@mikelehen
Copy link
Contributor

Thanks very much for the detailed report. We found this issue ourselves a few days ago and the fix was checked in as #810. There was indeed a race condition when rapidly doing writes after a permission denied failure. The fix should be included in the next Firebase iOS SDK release. Thanks again and sorry for your trouble!

@wilhuff
Copy link
Contributor

wilhuff commented Feb 22, 2018

(reopening because we haven't formally adopted #819 yet)

@ryanwilson
Copy link
Member

This fix is now live as part of the Firebase 4.10.0 release.

@firebase firebase locked and limited conversation to collaborators Nov 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants