firebase/agent-skills

firestore-rules-creation

Designs, authors, refactors, and hardens production-grade Cloud Firestore Security Rules (firestore.rules).

  • SKILL.md 已保存
  • 英文来源资料
  • 安装与运行未实测
先判断是否解决你的问题

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. 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.

以上为来源原文,中文用途说明尚待整理。

按客户端选择安装入口

怎么接入你的 Agent?

  1. 定位完整 Skill 目录

    打开本项目来源,核对 SKILL.md 及其引用的脚本和资料。

  2. 交给你正在用的 Agent

    在下面选择客户端,展开并复制安装指令,让 Agent 读取来源后选择安装方式。

  3. 确认识别,再做具体任务

    让 Agent 回报安装目录和识别到的名称 firestore-rules-creation,然后告诉 Agent 你的任务和实际输入,让它先核对触发条件。

展开并复制给 Codex 的安装指令
发送给 Codex

安装并检查 firestore-rules-creation

请在 Codex 的当前工作环境中安装并检查 firestore-rules-creation 这个 Skill。

项目身份:firebase/agent-skills / firestore-rules-creation
来源:https://github.com/firebase/agent-skills/blob/99954a30898bb5ddc8152ee10e124dc3b4106bf7/skills/firestore-rules-creation/SKILL.md
已定位的源文件:skills/firestore-rules-creation/SKILL.md

1. 先阅读真实 SKILL.md 和它引用的必要文件,确认触发条件、安装方式、依赖与权限;尊重源文件要求的审批步骤。
2. 按当前客户端支持的方式安装完整 Skill 目录,保留已有配置,不只复制一段提示词。涉及缺失凭证、目标目录或权限时先列出缺项并向我确认。
3. 安装后回读实际目录、Skill 名称和识别结果,说明哪些步骤已完成,哪些只是文档检查,不得把安装成功当作任务已经实测。
4. 如来源提供了可安全验证的示例,在我提供所需输入后做一个最小任务;创建、修改、删除、部署或发送内容前,按源文件和我的授权执行。
需要核对时再展开原文

来源原文与资料状态

源文件
已保存 SKILL.md,抓取于 2026-11-19T19:32:10.677Z
中文使用说明
尚待整理,保留英文来源内容
安装与任务测试
本站未执行安装或任务测试
来源复核
已保留来源记录;当前完整用法未逐项人工复核
展开 SKILL.md 原文、章节与历史收录资料

skills/firestore-rules-creation/SKILL.md · 抓取时间 2026-11-19T19:32:10.677Z

以下保留源文件的 description、章节及摘录,供核对中文说明;完整文件通过上方链接打开。

抓取成功不代表已完成安装或任务测试。

来源 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.

查看源文件章节 / Source sections
  • 原文:Firestore Security Rules Creation
  • 工作流程 / Workflow
  • 原文:Phase-1: Codebase Analysis
  • 原文:Phase-2: Security Rules Generation
  • 原文:Mandatory: User Data Separation (The "No Mixed Content" Rule)
  • 原文:**CRITICAL** RBAC Guidelines
  • 原文:Critical Directives for Secure Generation
  • 原文:Advanced Validation for Business Logic
  • 原文:1. Enforce Enum Values
  • 原文:2. Validate State Transitions
  • 原文:3. Strict Path and Relationship Scoping
  • 原文:4. Secure Counter Updates
  • 原文:5. **CRITICAL** Ensure Application Validity
  • 原文:Phase-3: Devil's Advocate Attack
  • 原文:Phase-4: Syntactic Validation
  • 原文:Critical Constraints
原文: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 1. **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:** ```javascript // =============================================================== // 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:**

本段为节选,完整内容见源文件。

原文: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: ```javascript 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() function will return true allow update: if (isOwner(userId) && isValidUser(request.resource.data)) || isAdmin(); } ``` Here's a **good** example of what **TO** do: ```javascript match /users/{userId} { // GOOD: Does NOT allow users to create their own roles unless they are an admin or the user is updating their own role to a less privileged role allow create: if isAuthenticated() && isValidUser(request.resource.data) && ((isOwner(userId) && request.resource.data.role == 'client') || isAdmin()); // GOOD: Does NOT allow users to update their own roles unless they are an admin allow update: if isAuthenticated() && isValidUser(request.resource.data) && ((isOwner(userId) && request.resource.data.role == resource.data.role) || isAdmin()); } ```

文件 SHA256:26056872489c535ac58e35de52bf76b14a13607fa57d57f0e6e85f1b0be7e583

仓库许可证记录:Apache-2.0;repository-license-recorded-scope-unverified,查看来源。

SKILL.md原文description · 2026-11-19T19:32:10.677Z

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.

查看历史简介来源

历史收录数据

来源仓库firebase/agent-skills
Skill源路径skills/firestore-rules-creation/SKILL.md

安装前请让使用的Agent先读取这个SKILL.md及其所在目录,确认依赖和所需权限。此页不生成未经来源验证的安装命令。

返回 Skills 目录,按任务继续筛选 · MCP与Skills教程与资源