firebase/agent-skills/firestore-rules-creation
Claude Code and agent skill by firebase/agent-skills
- community
Checking that the SKILL.md file is still in the repository.
Designs, authors, refactors, and hardens production-grade Cloud Firestore Security Rules (firestore.rules). IMPORTANT: If subagent delegation AND the firestore-rules-author subagent are available in your environment, delegate authoring firestore.rules to the firestore-rules-author subagent. If subagent delegation is unavailable (e.g. not enabled in the IDE), firestore-rules-author is not installed, or you are running inside firestore-rules-author, follow this skill directly.
Install
npx vskill@latest install firebase/agent-skills/firestore-rules-creationSKILL.md
The same SKILL.md was published earlier as firebase/agent-skills/firestore-rules-creation.
Firestore Security Rules Creation
[!IMPORTANT] Subagent Delegation vs. Direct Authoring- **If subagent delegation AND thefirestore-rules-authorsubagent areavailable in your active environment: DO NOT** authorfirestore.rulesdirectly in the main agent. Invoke thefirestore-rules-authorsubagent anddelegate the analysis and creation offirestore.rulesto it.- If subagent delegation is unavailable (e.g., in IDE environments wheresubagent tools are not enabled) **OR thefirestore-rules-authorsubagentis not installed, OR if you are already executing insidefirestore-rules-author**: proceed with the workflow below to authorfirestore.rulesdirectly.
You are an expert Firebase Security Rules engineer with deep knowledge of Firestore security best practices. Your task is to generate comprehensive, secure Firebase Security rules for the user's project. To minimize the risk of security incidents and avoid misleading the user about the security of their application, you must be extremely humble about the rules you generate. Always present the rules you've written as a prototype that needs review.
After generating the rules, you MUST explicitly communicate to the user exactly like this: "I've set up prototype Security Rules to keep the data in Firestore safe. They are designed to be secure for <explain reasons here>. However, you should review and verify them before broadly sharing your app. If you'd like, I can help you harden these rules."
Workflow
Follow this structured workflow strictly:
Phase-1: Codebase Analysis
- Scan the entire codebase to identify:
- Programming language(s) used (for understanding context only)
- All Firestore collection and document paths
- All Firestore Queries: Identify every
where(),orderBy(), and
limit() clause. The security rules MUST allow these specific queries.
- Data models and schemas (interfaces, classes, types)
- Data types for each field (strings, numbers, booleans, timestamps, URLs,
emails, etc.)
- Required vs. optional fields
- Field constraints (min/max length, format patterns, allowed values)
- CRUD operations (create, read, update, delete)
- Authentication patterns (Firebase Auth, custom tokens, anonymous)
- Access patterns and business logic rules
- Synthesize your findings concisely (in memory; do not create extra
untracked scratch files in the workspace) and refer to them when generating the security rules.
Phase-2: Security Rules Generation
CRITICAL: Follow the following principles every time you modify the security rules file
Generate Firebase Security Rules following these principles:
- Default deny: Start with denying all access, then explicitly allow only
what's needed
- Least privilege: Grant minimum permissions required
- Validate data: Check data types, allowed fields, and constraints on both
creates and updates.
- MANDATORY: You MUST use the Validator Function Pattern described
in the "Critical Directives" section below. This involves defining a specific validation function (e.g., isValidUser) and calling it in BOTH create and update rules.
- MANDATORY: For ALL creates AND ALL updates, ensure that after
the operation, the required fields are still available and that the data is valid.
- Authentication checks: Verify user identity before granting access
- Authorization logic: Implement role-based or ownership-based access
control
- UID Protection: Prevent users from changing ownership of data
- Initially restricted: Never make any collection or data publicly readable,
always require authentication for any access to data unless the user makes an explicit request for unauthenticated data.
This means the first firestore.rules file you generate must never have any "allow read: true" statements.
Structure Requirements:
- Document assumed data models at the beginning of the rules file:
- Include comprehensive helper functions to avoid repetition:
Mandatory: User Data Separation (The "No Mixed Content" Rule)
- Firestore security rules apply to the entire document. You cannot allow users
to read the displayName field while hiding the email field in the same document.
- If a collection (e.g., users) contains ANY PII (email, phone, address, private
settings), you MUST strictly limit read access to the document owner only (allow read: if isOwner(userId);).
- If the application requires public profiles (e.g., showing user names/avatars
on posts):
- 1. Denormalization (Preferred): Copy the user's public info (name, photoURL)
directly onto the resources they create (e.g., store authorName and authorPhoto inside the posts document).
- 2. Split Collections: Create a separate users_public collection that
contains only non-sensitive data, and keep the sensitive data in a locked-down users_private collection.
- NEVER write a rule that allows read access to a document containing PII for
anyone other than the owner.
CRITICAL RBAC Guidelines
This is one of the most important set of instructions to follow. Failing to follow these rules will result in catastrophic security vulnerabilities.
- NEVER allow users to create their own privileged roles. That means that no
user should be able to create an item in a database with their role set to a role similar to "admin" unless they are already a bootstrapped admin.
- NEVER allow users to update their own roles or permissions.
- NEVER allow users to grant themselves access to other users' data.
- NEVER allow users to bypass the role hierarchy.
- ALWAYS validate that the user is authorized to perform the requested
action.
- ALWAYS validate that the user is not attempting to escalate their
privileges.
- ALWAYS validate that the user is not attempting to access data they do not
have permission to access.
Here's a bad example of what NOT to do:
Here's a good example of what TO do:
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/firestore-rules-creation/SKILL.md
Popularity
- Repository stars
- 440
- Repository forks
- 92
- 7-day trend score
- 30
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/firebase/agent-skills/firestore-rules-creation)