Firestore Security Rules for The Italian Club

VerifiedSafe

Guidelines for writing or modifying Firestore security rules: auth required, bakery stamp, field validation, delete restrictions, default-deny. Deploy after changes.

Sby Skills Guide Bot
SecurityIntermediate
8/29/2026
Claude CodeCursorWindsurfCopilotCodex
#firestore#security-rules#firebase#access-control#schema-validation

Recommended for

Automated summary

A guide for writing or changing Firestore security rules in The Italian Club project, enforcing strict invariants: auth required, field validation, a `bakery == 'main'` stamp, deletes denied by default, and an untouchable trailing default-deny block.

Strengths

  • Ships numbered invariants plus two ready-to-adapt templates (history-keeping collection, mutable single document), so you don't start from a blank file.
  • Warns about the big `setDoc(merge: true)` / `updateDoc` trap: rules evaluate the full merged document, so `hasOnly()` must include retired fields and no field may be required.
  • Explicitly states that rules do not deploy with the GitHub Pages push and that `firebase deploy --only firestore:rules` must follow every change.
  • Is candid about the Anonymous Auth limitation: `request.auth != null` proves no identity, so per-user isolation is not yet possible.

Limitations

  • Highly specific to The Italian Club project and its collections; the templates and the `bakery` stamp do not transfer as-is.
  • Does not supply the real production field list — it requires reading live documents before writing the whitelist, which the agent cannot do on its own.
  • Does not cover designing genuinely per-user scoped rules, which would first require non-anonymous authentication.
When to use it

Use it whenever a Firestore collection is added or changed, or when `firestore.rules` is edited, reviewed, or deployed in this project.

When not to use it

Avoid it for a different project, or when designing per-user access rules that assume real rather than anonymous authentication.

Security analysis

Safe
Quality score93/100

The skill provides guidance and templates for writing Firestore security rules for a specific application. It does not instruct destructive, exfiltrating, or obfuscated actions. The only commands mentioned are firebase deploy and emulator test commands, which are legitimate deployment and testing steps. No allowed tools are declared, so the skill itself does not enable execution; even if executed, the commands are standard and safe for the intended workflow.

No concerns found

How this analysis is made

Examples

New collection rules
Add an `invoices` collection to firestore.rules with fields `numero` (string), `importo` (number) and `tipo` (string). Apply the shared-collection template: auth required, bakery == 'main', deletes denied, default-deny block untouched — then deploy the rules.
Review a whitelist change
We added `notifyHoursBefore` to suppliers. Review firestore.rules: check the hasOnly whitelist against what the app actually writes, flag any retired field I forgot, and deploy once it's correct.
Mutable draft document
We're adding a new single document that gets rewritten with setDoc(merge: true) and updateDoc. Write its Firestore rules and explain why no field can be required and why delete stays denied.

name: firestore-rules description: How to write or change Firestore security rules for The Italian Club. Use whenever a new Firestore collection is added, an existing one is changed, or firestore.rules is edited or reviewed. Every collection must require auth, validate its fields, carry bakery == 'main', restrict deletes, and the trailing default-deny block must never be weakened. After any change, the rules must be deployed.

Firestore security rules — The Italian Club

All security is enforced server-side in firestore.rules. The app uses Anonymous Auth, so request.auth != null only means "some app client", never a specific person. Identity-based isolation is NOT possible at the rules level yet — it needs real (non-anonymous) auth, which is a later step. Until then, rules harden validation and the bakery stamp, not per-user read scope.

Invariants — true for EVERY collection

  1. Auth required on every read and write: request.auth != null.
  2. Bakery stamp: every Orders-system document carries bakery and writes must validate it: request.resource.data.bakery == 'main'. This is forward-compatible with future per-bakery isolation.
  3. Field validation on create/update: restrict the allowed keys and check each field's type/size. Never accept an open-ended payload.
  4. Deletes denied by default (allow delete: if false;). Only allow delete where the data model overwrites/clears by design (e.g. the current draft).
  5. Default-deny stays last and untouched: the trailing match /{document=**} { allow read, write: if false; } must always remain. Never remove or loosen it — it locks down any collection not explicitly listed.
  6. Deploy after every change: firebase deploy --only firestore:rules (rules do NOT deploy automatically with the GitHub Pages push).

Templates

A. Shared collection that keeps history (no delete)

Use for reference/records like suppliers, ingredients, orders-history.

match /NEW_COLLECTION/{id} {
  allow read: if request.auth != null;
  allow create, update: if request.auth != null
    && request.resource.data.bakery == 'main'
    && request.resource.data.keys().hasOnly(['bakery', 'FIELD_A', 'FIELD_B'])
    && request.resource.data.FIELD_A is string
    && request.resource.data.FIELD_A.size() < 200;
  allow delete: if false;
}

B. Mutable single document, overwritten on every change (delete still denied)

Use for draft-style data rewritten constantly, like drafts/current.

⚠️ Delete stays denied even here. drafts/current used to be deleted when the week was archived, but since v179 nothing in the app deletes it — clearSupplier removes only that supplier's keys with deleteField(). Allowing delete would leave a way to wipe an order in progress and nothing that needs it.

⚠️ Anything written with setDoc(merge: true) or updateDoc — which is what saveDoc/clearFields use — is seen by the rules as the FULL MERGED document, not the patch. Two consequences, both learnt the hard way:

  • hasOnly() must list every field a live document was EVER given, retired ones included. A merge write never deletes a field, so retired fields are still there. drafts/current still carries weekId from the weekly model; suppliers still carry notifyHoursBefore. Omit one and every future write to that document is refused.
  • No field may be required, because a partial write ({ active } from Deactivate) merges onto a document that may predate that field.

Read the real production documents before writing the whitelist. Do not infer it.

match /NEW_COLLECTION/{id} {
  allow read: if request.auth != null;
  allow create, update: if request.auth != null
    && request.resource.data.bakery == 'main'
    && request.resource.data.keys().hasOnly(['bakery', 'FIELD_A', 'RETIRED_FIELD'])
    && (!('FIELD_A' in request.resource.data)
        || (request.resource.data.FIELD_A is map
            && request.resource.data.FIELD_A.size() <= 2000));
  allow delete: if false;
}

By contrast, a collection written WHOLE (setDoc without merge, or a transaction's tx.set — like orders-history) sees only the payload, so hasOnly is exact and fields CAN be required. Template A covers that case.

C. Data tied to a person (future — Step 2 PIN login)

PIN login is app-level, NOT Firebase Auth, so anonymous auth still cannot prove identity. Store the staff identity as a VALIDATED FIELD, and be honest that the rules cannot enforce "only this person": they validate shape, not ownership. Real ownership enforcement waits for real auth.

match /NEW_COLLECTION/{id} {
  allow read: if request.auth != null;
  allow create, update: if request.auth != null
    && request.resource.data.bakery == 'main'
    && request.resource.data.staffId is string
    && request.resource.data.staffId.size() > 0;
  allow delete: if false;
}

How to add or tighten a collection (checklist)

  1. Read the real production documents FIRST if the collection already has data — the union of their field names is the whitelist. Inferring it from the code misses retired fields, and the resulting refusal is silent and permanent.
  2. Work out how the collection is written (merge vs whole) — that decides whether fields may be required. See template B.
  3. Pick the matching template (A, B, or C).
  4. Add the match block ABOVE the default-deny block, never below it.
  5. List the exact allowed keys (including bakery) and validate each field.
  6. Keep bakery == 'main' on every write.
  7. Leave the trailing default-deny exactly as it is.
  8. Test against the emulator before deploying: firebase emulators:exec --only auth,firestore "npm run test:rules" (tests/rules/firestore-rules-check.mjs). Add cases for the new collection, covering the legacy shapes as well as the current one. Then break a rule on purpose and confirm a test notices — a suite that passes whatever the rules say is worthless.
  9. Deploy: firebase deploy --only firestore:rules.
  10. Tell the user the collection name, the rule added, and to run the deploy.

Never

  • Never add allow read, write: if true or any rule without request.auth.
  • Never remove or weaken the default-deny block.
  • Never claim the rules enforce per-person/per-bakery isolation under anonymous auth — they do not.

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/firestore-security-rules-for-the-italian-club-mte1lgx6/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/firestore-security-rules-for-the-italian-club-mte1lgx6' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/firestore-security-rules-for-the-italian-club-mte1lgx6/download' --output '.skill-downloads/firestore-security-rules-for-the-italian-club-mte1lgx6/SKILL.md.part' && mv '.skill-downloads/firestore-security-rules-for-the-italian-club-mte1lgx6/SKILL.md.part' '.skill-downloads/firestore-security-rules-for-the-italian-club-mte1lgx6/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/firestore-security-rules-for-the-italian-club-mte1lgx6/SKILL.md' && test -s '.skill-downloads/firestore-security-rules-for-the-italian-club-mte1lgx6/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/firestore-rules' && cp -R '.skill-downloads/firestore-security-rules-for-the-italian-club-mte1lgx6' '.claude/skills/firestore-rules'

Cursor
test -f '.skill-downloads/firestore-security-rules-for-the-italian-club-mte1lgx6/SKILL.md' && test -s '.skill-downloads/firestore-security-rules-for-the-italian-club-mte1lgx6/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/firestore-rules' && cp -R '.skill-downloads/firestore-security-rules-for-the-italian-club-mte1lgx6' '.cursor/skills/firestore-rules'

Codex
test -f '.skill-downloads/firestore-security-rules-for-the-italian-club-mte1lgx6/SKILL.md' && test -s '.skill-downloads/firestore-security-rules-for-the-italian-club-mte1lgx6/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/firestore-rules' && cp -R '.skill-downloads/firestore-security-rules-for-the-italian-club-mte1lgx6' '.agents/skills/firestore-rules'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/firestore-security-rules-for-the-italian-club-mte1lgx6'

openskills read 'firestore-security-rules-for-the-italian-club-mte1lgx6'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/firestore-security-rules-for-the-italian-club-mte1lgx6/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills