---
name: firebase-rules-security-auditor
description: "Writes strict Firebase Security Rules for your data model and explains each check, so access is limited to exactly who should have it. Use when a Firebase developer needs security rules written or tightened for a collection or path, with an explanation of each check. Do not use for deploying rules or writing application code for the client. Related topics: firebase, security, coding."
---

# Firebase Rules Security Auditor

Writes strict Firebase Security Rules for your data model and explains each check, so access is limited to exactly who should have it.

## When to use

Use this skill when a Firebase developer needs security rules written or tightened for a collection or path, with an explanation of each check. Do not use it for deploying rules or writing application code for the client.

## Workflow

1. Ask the user for each input listed below in a single message, skipping any they have already given. Where options are listed, offer them, but accept other answers too.
2. Begin with a default deny rule for the product chosen.
3. Write separate create, update and delete rules matching the read and write requirements.
4. Add validation for the selected constraints and make protected fields immutable by comparing new and existing data.
5. Explain each rule in plain language and list three requests the rules must reject.

## Inputs

- **Firebase product** (choose one: Firestore, Realtime Database, Cloud Storage)
- **Target collection or path** (free text, e.g. "users/userId")
- **Data model** (longer free text)
- **Who can read** (choose one: Public, Authenticated Users, Only Owner, Admin Only)
- **Who can write** (choose one: Authenticated Users, Only Owner, Admin Only, No One)
- **Extra constraints** (choose any: Validate data types, Check string length, Prevent field updates, Require specific fields)
- **Using custom claims such as admin** (choose one: Yes, No)

## Output

The rules in a code block, a one-line explanation per rule, and three example requests that should be denied with the reason.

## Prompt template

Fill the inputs into this template and follow it as the full instruction.

### Firebase Security Rules Writer

Write strict, secure Firebase Security Rules for the data model below and explain the logic.

- Firebase product: {{Firebase product}}
- Target collection or path: {{Target collection or path}}
- Data model: {{Data model}}
- Who can read: {{Who can read}}
- Who can write: {{Who can write}}
- Extra constraints: {{Extra constraints}}
- Using custom claims such as admin: {{Using custom claims such as admin}}

Start from deny by default and allow only the operations named. Split write into create, update and delete rather than one broad rule, since they usually need different checks. Compare the incoming data against existing data for immutable fields, and validate types, lengths and required keys on create and update. Use the custom claim in the rule for admin access when requested, never a field the client can write. Use the syntax of the product chosen.

Output the rules in a code block, then a short explanation for each rule, then three requests that should be denied and why.

## Pitfalls

- Granting write with a single broad rule when create, update and delete need different checks.
- Trusting an admin or role field the client can edit instead of a custom claim.
- Leaving a catch-all allow rule from the console defaults in place.
