How to Configure Firestore Data Masking

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up firestore data masking, you must rewrite sensitive fields before returning documents. Firestore lacks native field masking and sends the whole document when a read passes. Teams often split collections or build backend functions to clean up query results. When permissions are too broad, one document read exposes emails and phone numbers. How to set up a firestore data masking workflow In Firestore, security rules work at the document level, not the field level. If a user can read a

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

To set up firestore data masking, you must rewrite sensitive fields before returning documents. Firestore lacks native field masking and sends the whole document when a read passes. Teams often split collections or build backend functions to clean up query results. When permissions are too broad, one document read exposes emails and phone numbers.

How to set up a firestore data masking workflow

In Firestore, security rules work at the document level, not the field level. If a user can read a document, the database sends every field inside. The database cannot hide a card number while showing the rest of the record.

Because of this design, teams build custom patterns to handle sensitive fields. The most common setup splits each record into public and private collections. You store safe data in one document and national IDs in a restricted collection. Security rules then check the user role before allowing reads on the private path.

Another approach routes all client reads through a backend server or cloud function. The client app asks the backend for a user profile or order record. The backend reads the full document from the database using an admin role. Code in the backend then rewrites matched fields like emails and phone numbers. After the function replaces those strings with masked values, it sends the safe response.

Some teams also copy production documents into a second project for testing. A background job reads new records, scrubs card numbers, and writes the clean copy. Developers then run tests against the clean database project without touching live customer records.

Where native collection splitting falls short

Splitting documents and writing backend wrappers works well for standard client apps. Mobile and web users only hit the paths that your code allows. Still, this setup only decides who can log in to the database project.

Engineers, support staff, and data scripts often bypass client rules during daily work. They use cloud roles that grant read rights across all collections in the project. Cloud roles do not check individual documents or filter out private subcollections. Once an engineer logs in with a reader role, every query returns full records.

Data Masking (Static) + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

The native setup does not inspect what individual queries do in flight. If an engineer queries a collection to fix a bug, the whole document returns. Raw emails, phone numbers, and card numbers appear on their screen right away. Maintaining duplicate masked databases also adds extra storage costs and sync delays. Teams need a way to rewrite sensitive fields in query results at runtime.

How to handle field masking for live database reads

To protect live reads without changing your schema, masking must happen in transit. Instead of splitting every document into two collections, keep your data model simple. Let your database store the full record in one place as normal.

When a developer or support tool runs a read query, inspect the response payload. Pattern matchers can scan the returned fields for emails, card numbers, and national IDs. The system then rewrites matched fields in results before they reach the user screen. This approach keeps raw values out of local logs and developer laptops during support.

Add runtime guardrails and masking beside your databases and APIs

Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits inline in the protocol beside the service as an open-source proxy, a sidecar for your database or API. On every production query an agent or human runs, hoop.dev decides whether to pass, mask, block, or escalate it for review.

Before a query runs, hoop.dev guardrails check the statement against your rules, an AI Analyzer you configure can score intent or hold risky calls for human approval, and hoop.dev data masking rewrites sensitive fields in responses in memory. Explore the MIT-licensed project on GitHub.

Frequently asked questions

Does Firestore have built-in field-level data masking?

No, Firestore does not have native field-level masking for read queries. Security rules approve or deny access to the entire document as a whole. To mask specific fields, you must split collections or rewrite results in transit.

Can Cloud IAM roles hide specific fields from engineers?

No, Cloud IAM roles grant permissions at the project or database level. An engineer with a viewer role can read all fields in every collection. IAM checks who logs in, but it does not rewrite query results.

Which fields should teams mask in document query results?

Teams should focus on structured identifiers that create risk when exposed in logs. Common examples include emails, phone numbers, credit card numbers, and national IDs. Rewriting these matched fields in results keeps everyday debugging and support work safe.

The query runs. The emails stay hidden.