SkillAgentSearch skills...

firestore-rules-creation

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.

Install / Use

npx skills add firebase/agent-skills --skill firestore-rules-creation

Installs into whichever agent you are using.

About this skill
📄

SKILL.md

Installable skill definition

Quality Score

91/100

Category

Security

Supported Platforms

Universal

Our assessment of firestore-rules-creation

firestore-rules-creation scores 91/100 on our quality scale, 453rd of 1,094 Security skills we index (top 42%).

Its SKILL.md is 27 KB long, well organised into 16 sections with 8 code examples: a thorough specification that gives an agent plenty to work with.

It has 454 GitHub stars, a meaningful sign that others use it.

Substance
30/30
Structure
20/20
Description
15/15
Adoption
11/20
Freshness
15/15

Maintenance, license and trust

  • The repository was last updated about 2 months ago, so firestore-rules-creation is actively maintained.
  • Our last check on 2026-10-29 found the source still online.
  • It is released under the Apache-2.0 license, a permissive license that allows use, modification and commercial use with attribution.
  • Its trust signals score 100/100, with no cautions. These come from repository metadata, not a code audit — read the skill file before letting an agent act on it.

Safety scan

No issues found

Our scan of the whole file found no instruction hijacking, hidden characters, credential access, data exfiltration or destructive commands. An AI review of the same text found nothing harmful.

AI review by kimi-k2.7-code on 2026-10-05. Automated pattern scan on 2026-10-05. It catches known dangerous patterns, not every risk — read a skill before letting an agent act on it.

firestore-rules-creation compared with similar skills

All 4 of these similar skills score higher than firestore-rules-creation; compare them before choosing.

SkillScoreStarsUpdatedFormat
firestore-rules-creation (this skill)by firebase9145455d agoSKILL.md
taste-skillby Leonxlnx100117.8k9d agoCLAUDE.md
Claude-Code-Game-Studiosby Donchitos10040.0k8d agoCLAUDE.md
algorithmic-artby anthropics100177.9k56d agoSKILL.md
pptxby anthropics100177.9k56d agoSKILL.md

Frequently asked questions

How do I install firestore-rules-creation?
Run npx skills add firebase/agent-skills --skill firestore-rules-creation. The install tabs above show the steps for each supported agent.
Which AI agents does firestore-rules-creation work with?
It is written for Universal, as a SKILL.md file. Other agents that read the same format can often use it too.
Is firestore-rules-creation safe to use?
Our scan of the whole file found no instruction hijacking, hidden characters, credential access, data exfiltration or destructive commands. An AI review of the same text found nothing harmful. It is Apache-2.0-licensed and scores 100/100 on trust signals. Skills are instructions an agent will follow, so read the file before installing it and do not approve commands you do not understand.
Is firestore-rules-creation still maintained?
The repository was last updated about 2 months ago, so firestore-rules-creation is actively maintained.

name: firestore-rules-creation description: >- 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. metadata: category: Databases

Firestore Security Rules Creation

[!IMPORTANT] Subagent Delegation vs. Direct Authoring

  • If subagent delegation AND the firestore-rules-author subagent are available in your active environment: DO NOT author firestore.rules directly in the main agent. Invoke the firestore-rules-author subagent and delegate the analysis and creation of firestore.rules to it.
  • If subagent delegation is unavailable (e.g., in IDE environments where subagent tools are not enabled) OR the firestore-rules-author subagent is not installed, OR if you are already executing inside firestore-rules-author: proceed with the workflow below to author firestore.rules directly.

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

  1. 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
  2. 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:

  1. Document assumed data models at the beginning of the rules file:
// ===============================================================
// Assumed Data Model
// ===============================================================
//
// This security rules file assumes the following data structures:
//
// Collection: [name]
// Document ID: [pattern]
// Fields:
//   - field1: type (required/optional, constraints) - description
//   - field2: type (required/optional, constraints) - description
//   [List all fields with types, constraints, and whether immutable]
//
// [Repeat for all collections]
//
// ===============================================================
  1. Include comprehensive helper functions to avoid repetition:
// ===============================================================
// Helper Functions
// ===============================================================
//
// Check if the user is authenticated
function isAuthenticated() {
   return request.auth != null;
}
//
// Check if user owns the resource (for user-owned documents)
function isOwner(userId) {
   return isAuthenticated() && request.auth.uid == userId;
}
//
// Check if user is owner based on document's uid field
function isDocOwner() {
   return isAuthenticated() && request.auth.uid == resource.data.uid;
}
//
// Verify UID hasn't been tampered with on create
function uidUnchanged() {
   return !('uid' in request.resource.data) ||
     request.resource.data.uid == request.auth.uid;
}
//
// Ensure uid field is not modified on update
function uidNotModified() {
   return !('uid' in request.resource.data) ||
     request.resource.data.uid == resource.data.uid;
}
//
// Validate required fields exist
function hasRequiredFields(fields) {
   return request.resource.data.keys().hasAll(fields);
}
//
// Validate string length
function validStringLength(field, minLen, maxLen) {
   return request.resource.data[field] is string &&
     request.resource.data[field].size() >= minLen &&
     request.resource.data[field].size() <= maxLen;
}
//
// Validate URL format (must start with https:// or http://)
function isValidUrl(url) {
   return url is string &&
     (url.matches("^https://.*") || url.matches("^http://.*"));
}
//
// Validate email format
function isValidEmail(email) {
   return email is string &&
     email.matches("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$");
}

//
// Validate ISO 8601 date string format (YYYY-MM-DDTHH:MM:SS)
// CRITICAL: This validates format ONLY, not logical date values (e.g., month 13).
// Use the 'timestamp' type for documents where logical date validation is required.
function isValidDateString(dateStr) {
  return dateStr is string &&
    dateStr.matches("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.*Z?$");
}

//
// Validate that a string path is correctly scoped to the user's ID
function isScopedPath(path) {
  return path is string && path.matches("^users/" + request.auth.uid + "/.*");
}
//
// Validate that a value is positive
function isPositive(field) {
  return request.resource.data[field] is number && request.resource.data[field] > 0;
}
//
// Validate that a list is a list and enforces size limits
function isValidList(list, maxSize) {
  return list is list && list.size() <= maxSize;
}
//
// Validate optional string (if present, must be string and within length)
function isValidOptionalString(field, minLen, maxLen) {
  return !(field in request.resource.data) ||
         (request.resource.data[field] is string &&
          request.resource.data[field].size() >= minLen &&
          request.resource.data[field].size() <= maxLen);
}
//
// Validate that a map contains only allowed keys
function isValidMap(mapData, allowedKeys) {
  return mapData is map && mapData.keys().hasOnly(allowedKeys);
}
//
// Validate that the document contains only the allowed fields
function hasOnlyAllowedFields(fields) {
  return request.resource.data.keys().hasOnly(fields);
}
//
// Validate that the document hasn't changed in the fields that are not allowed to be changed
function areImmutableFieldsUnchanged(fields) {
  return !request.resource.data.diff(resource.data).affectedKeys().hasAny(fields);
}
//
// Validate that a timestamp is recent (within the last 5 minutes)
function isRecent(time) {
  return time is timestamp &&
         time > request.time - duration.value(5, 'm') &&
         time <= request.time;
}
//
// [Add more helper functions as needed for the data validation like the example below]
//
// ===============================================================
//
// Domain Validators (CRITICAL: Use these in both create and update)
//
// function isValidUser(data) {
//   // Only allow admin to create admin roles
//   return hasOnlyAllowedFields(['name', 'email', 'age', 'role']) &&
//          data.name is string && data.name.size() > 0 && data.name.size() < 50 &&
//          data.email is string && isValidEmail(data.email) &&
//          data.age is number && data.age >= 18 &&
//          data.role in ['admin', 'user', 'guest'];
// }

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).
      1. 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:

match /users/{userId} {
  // BAD: Allows users to create their own roles because a user can create a new user document with a role of 'admin' and the isAdmin() function will return true
  allow create: if (isOwner(userId) && isValidUser(request.resource.data)) || isAdmin();
  // BAD: Allows users to update their own roles because a user can update their own user document with a role of 'admin' and the isAdmin() functio

Truncated for display — read the full file on GitHub.

Related Skills

View on GitHub
GitHub Stars454
CategorySecurity
Updated1mo ago
Forks99

Languages

JavaScript

Trust signals

100/100

From repository metadata: license, adoption, age and documentation. Not a code audit — see the Safety scan above for what the skill file itself contains.

No cautions