Skip to content

Firestore crash on invalid permissions #536

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
nitrag opened this issue Dec 6, 2017 · 4 comments
Closed

Firestore crash on invalid permissions #536

nitrag opened this issue Dec 6, 2017 · 4 comments
Assignees

Comments

@nitrag
Copy link

nitrag commented Dec 6, 2017

  • Xcode version: 9.1
  • Firebase SDK version: 4.7
  • Firebase Component: Firestore
  • Component version: 0.9.3

Calling .setData() on a Document with invalid permissions (on the backend database rules) results in a hard crash.

    func updateUser(){
        var refresh: [String : Any] = [
            "first_name": self.api_user.user.first_name,
            "last_name": self.api_user.user.last_name,
            "username": self.api_user.user.username,
            "last_active": Date()
        ]
        self.db.collection("users").document(self.firebase_user.uid).setData(refresh, options: SetOptions.merge()) { err in
            if let err = err {
                print("error: \(err)")
            }else{
                print("SUCCESS FirestoreClient.updateUser")
            }
        }
    }

Crash:

    ERROR FirestoreClient.updateUser: Missing or insufficient permissions.
    2017-12-05 18:42:08.963700-0500 MeetYouThere[77409:2346136] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'FIRESTORE INTERNAL ASSERTION FAILED: Delegate must be nil'
    *** First throw call stack:
    (
        0   CoreFoundation                      0x0000000103ee21ab __exceptionPreprocess + 171
        1   libobjc.A.dylib                     0x0000000103577f41 objc_exception_throw + 48
        2   CoreFoundation                      0x0000000103ee7372 +[NSException raise:format:arguments:] + 98
        3   Foundation                          0x000000010301c089 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
        4   MeetYouThere                        0x0000000100bd0807 -[FSTStream startWithDelegate:] + 722
        5   MeetYouThere                        0x0000000100bd2e4f -[FSTWriteStream startWithDelegate:] + 82
        6   MeetYouThere                        0x0000000100bc6661 -[FSTRemoteStore startWriteStream] + 84
        7   MeetYouThere                        0x0000000100bc70a5 -[FSTRemoteStore writeStreamWasInterruptedWithError:] + 244
        8   MeetYouThere                        0x0000000100bd2eef -[FSTWriteStream notifyStreamInterruptedWithError:] + 79
        9   MeetYouThere                        0x0000000100bd14b1 -[FSTStream closeWithFinalState:error:] + 657
        10  MeetYouThere                        0x0000000100bd1d46 -[FSTStream handleStreamClose:] + 144
        11  MeetYouThere                        0x0000000100bd22a6 __37-[FSTStream writesFinishedWithError:]_block_invoke + 69
        12  libdispatch.dylib                   0x0000000107b363f7 _dispatch_call_block_and_release + 12
        13  libdispatch.dylib                   0x0000000107b3743c _dispatch_client_callout + 8
        14  libdispatch.dylib                   0x0000000107b3f95b _dispatch_queue_serial_drain + 1162
        15  libdispatch.dylib                   0x0000000107b402df _dispatch_queue_invoke + 336
        16  libdispatch.dylib                   0x0000000107b3c07d _dispatch_queue_override_invoke + 733
        17  libdispatch.dylib                   0x0000000107b431f9 _dispatch_root_queue_drain + 772
        18  libdispatch.dylib                   0x0000000107b42e97 _dispatch_worker_thread3 + 132
        19  libsystem_pthread.dylib             0x0000000107ff65a2 _pthread_wqthread + 1299
        20  libsystem_pthread.dylib             0x0000000107ff607d start_wqthread + 13
    )
    libc++abi.dylib: terminating with uncaught exception of type NSException

Here are the incorrect Firestore Rules. I have since corrected the rules to be valid and the iOS app no longer crashes, however, that's not a long term solution.

  service cloud.firestore {
     match /databases/{database}/documents {
       match /users/{userId} {
         allow read, write: if get(/databases/$(database)/documents/users/$(request.auth.uid)).data.isAdmin == true;
         allow read, write: if auth != null && auth.uid == $userId;
         allow create: if request.auth != null;
       }
     }
   }
@ghost
Copy link

ghost commented Dec 12, 2017

I've also experienced this issue frequently when calling setData() on a document with invalid permissions. As a workaround for now, I've had to make some very careful checks in my code before writing to Firestore - definitely not an ideal long solution.

@jaysquared
Copy link

jaysquared commented Dec 12, 2017

I have the same problem. An update would work a couple of times, before the it crashes eventually. Even when changing the rules to wide open:

match /Rounds/{roundId} {
    allow read: if true;
    allow create: if false;
    allow update: if true;
    allow delete: if false;
}

@schmidt-sebastian schmidt-sebastian self-assigned this Dec 12, 2017
@schmidt-sebastian
Copy link
Contributor

Thanks for reporting this. This is likely already fixed with #510, which will be part of our next release. I will try to see if I can re-produce this issue with and without this PR.

@schmidt-sebastian
Copy link
Contributor

The fix for this has been released as part of 4.8.0.

@firebase firebase locked and limited conversation to collaborators Nov 10, 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

5 participants