firestore-validate-rules Tool
A “firestore-validate-rules” tool validates Firestore security rules syntax and semantic correctness without deploying them. It provides detailed error reporting with source positions and code snippets.
2 minute read
About
The firestore-validate-rules tool validates Firestore security rules syntax
and semantic correctness without deploying them. It provides detailed error
reporting with source positions and code snippets.
Use Cases
- Pre-deployment validation: Validate rules before deploying to production
- CI/CD integration: Integrate rules validation into your build pipeline
- Development workflow: Quickly check rules syntax while developing
- Error debugging: Get detailed error locations with code snippets
Compatible Sources
This tool can be used with the following database sources:
| Source Name |
|---|
| Firestore Source |
Parameters
| parameters | type | required | description |
|---|---|---|---|
| source | string | true | The Firestore Rules source code to validate |
Example
kind: tools
name: firestore-validate-rules
type: firestore-validate-rules
source: <firestore-source-name>
description: "Checks the provided Firestore Rules source for syntax and validation errors"
Output Format
The tool returns a ValidationResult object containing:
{
"valid": "boolean",
"issueCount": "number",
"formattedIssues": "string",
"rawIssues": [
{
"sourcePosition": {
"fileName": "string",
"line": "number",
"column": "number",
"currentOffset": "number",
"endOffset": "number"
},
"description": "string",
"severity": "string"
}
]
}
Advanced Usage
Authentication
This tool requires authentication if the source requires authentication.
Example Usage
Validate simple rules
{
"source": "rules_version = '2';\nservice cloud.firestore {\n match /databases/{database}/documents {\n match /{document=**} {\n allow read, write: if true;\n }\n }\n}"
}
Example response for valid rules
{
"valid": true,
"issueCount": 0,
"formattedIssues": "✓ No errors detected. Rules are valid."
}
Example response with errors
{
"valid": false,
"issueCount": 1,
"formattedIssues": "Found 1 issue(s) in rules source:\n\nERROR: Unexpected token ';' [Ln 4, Col 32]\n```\n allow read, write: if true;;\n ^\n```",
"rawIssues": [
{
"sourcePosition": {
"line": 4,
"column": 32,
"currentOffset": 105,
"endOffset": 106
},
"description": "Unexpected token ';'",
"severity": "ERROR"
}
]
}
Troubleshooting
The tool will return errors for:
- Missing or empty
sourceparameter - API errors when calling the Firebase Rules service
- Network connectivity issues
Additional Resources
- firestore-get-rules: Retrieve current active rules
- firestore-query-collection: Test rules by querying collections
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.