We all know that securing your database from malicious or misguided clients is critical. And with Security Rules for Cloud Firestore, you can create a very powerful access control system with simple matching syntax and logic.
Until now, however, testing your rules was difficult. You couldn’t test your rules before deploying them, and running arbitrary tests against these rules (to ensure they worked the way you expected) wasn’t easy, either.
Today, we’re pleased to announce our first big step in making it easier to secure your Cloud Firestore database with the release of the Rules Simulator.
Rules Simulator
With the new Rules Simulator in the Firebase console, you can test your rules as you write them — and before you deploy!
The simulator lets you test document reads, writes, and deletes against any part of your Cloud Firestore database. It will also let you simulate being signed in with a particular userID, so you can better test user-based access control. And for more sophisticated auth-based security, the simulator will help you build authentication tokens for various providers, giving you a preview of what that token will look like and allowing you to directly map the shape of the token to the rules you are writing.
The simulator tests against the rules as they are currently drafted in your editor, not as they are in deployment, allowing you to rapidly test different rules with different types of requests. This means that next time you click the publish button, you can have more confidence that your rules are protecting your data and doing exactly what you expect them to do!
You can get started today with the simulator by navigating over to the Rules section of the Firestore panel in the console.
Raising document access limits
We’ve also significantly increased the number of get()
, exists()
and getAfter()
calls you can make in each security rule. For a single document request, you can now make 10 document access calls (up from 3). For multi-resource requests, such as batched writes, you’ll be able to make a total of 20 document access calls for all documents in that request.
Check out our documentation for more information and examples.
Improved reference documentation
Firestore Security Rules may look like JavaScript, but they’re actually a purpose-built language with its own unique syntax and behavior. While we’ve always provided guides to help you write security rules, many developers mentioned to us that it is too hard to discover all of the functions, types, and edge-cases that you need to learn in order to write complex rules.
That’s why we published comprehensive reference documentation on the security rules language and the built-in types and functions that it provides. We hope this will enable you to be more confident when writing advanced rules conditions.