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.

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

  1. Pre-deployment validation: Validate rules before deploying to production
  2. CI/CD integration: Integrate rules validation into your build pipeline
  3. Development workflow: Quickly check rules syntax while developing
  4. 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

parameterstyperequireddescription
sourcestringtrueThe 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 source parameter
  • API errors when calling the Firebase Rules service
  • Network connectivity issues

Additional Resources