How to Configure Firestore Column Level Security

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up firestore column level security, split private fields into a separate subcollection. Firestore rules cannot hide single fields when a user reads a document. Most teams store all user data inside one flat document at first. When a role is too broad, any read pulls back every single field. This exposes private data like emails, phone numbers, and card numbers to the client app. How firestore column level security works in practice In relational databases, you can block access to one s

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 column level security, split private fields into a separate subcollection. Firestore rules cannot hide single fields when a user reads a document. Most teams store all user data inside one flat document at first. When a role is too broad, any read pulls back every single field. This exposes private data like emails, phone numbers, and card numbers to the client app.

How firestore column level security works in practice

In relational databases, you can block access to one specific column. Firestore is a document database, so a read operation returns the whole document. If a rule allows a read, the client gets every field inside that document. You cannot write a read rule that strips out just one secret field.

To fix this for reads, you must change how you group your data. Move public fields into a main collection and private fields into a subcollection. Then write separate read rules for the main document and the private subcollection. Standard users read the main document, while admins read the private subcollection too.

Write rules work in a different way than read rules. When a user updates a document, your rules can check which fields changed. You can compare the incoming field list against the existing document fields. If a normal user tries to change a protected field, the rule rejects the write. This lets you enforce field-level write limits without splitting the document in two.

What native rules solve and where gaps remain

Splitting documents works well for mobile and web apps that use client SDKs. It stops regular app users from pulling down private fields over the network. Field-level write rules also stop untrusted clients from changing sensitive status flags or roles.

Still, this native setup leaves a major gap for backend services and engineers. Backend servers and admin scripts often use service accounts with broad project roles. These roles bypass client security rules and read full documents across all collections. Once an engineer or script logs in with that role, every field is open.

Column-Level Encryption + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Native project roles only decide who can log in to the database. They do not inspect what individual queries or commands do in flight. If a support engineer runs a query to check a bug, they get everything. Raw emails, phone numbers, and national IDs return in the query results. Splitting collections also adds extra reads and makes app queries harder to maintain. Teams need a way to control data in flight and mask matched fields in results.

Best practices for structuring sensitive document fields

Keep your data model simple by grouping fields by who needs to read them. Put public profile data in one document and billing details in a locked subcollection. Never store card numbers or national IDs in the same document as public usernames.

Review your backend service accounts and remove broad project roles that bypass rules. Give each backend app a narrow role that only fits its specific job. Audit your database logs often to see which accounts read your private subcollections. Combine clean data models with runtime controls to keep private fields safe during debug sessions.

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

Can Firestore security rules hide a single field during a read?

No, a read rule applies to the entire document all at once. If a user has permission to read a document, they receive every field inside it. You must move secret fields to a separate document or subcollection to hide them.

How do you block users from updating specific fields in a document?

You can write a security rule that checks the incoming write request. The rule compares the changed fields against an allowed list of editable fields. If the request touches a restricted field, the database blocks the entire update.

Do backend admin SDKs follow Firestore security rules?

No, backend SDKs that use service accounts bypass client security rules by default. Their access depends on cloud project roles instead of document rules. You need extra controls to limit what engineers and scripts do with those accounts.

The query runs. The emails stay hidden.