Software Development
Hardening Firestore Write Security in a Solo-Built App
This post is deliberately general. I'm not going to describe Tracademic's actual data model, field names or rules — that would be a gift to anyone looking for a way in, not a useful lesson. What I can share is the principle behind the overhaul, because it's a mistake I suspect a lot of solo developers make on the way to their first real users.
Why the early rules were too loose
When you're the only person building an app, security rules tend to grow the same way the rest of the schema does: reactively. You add a field because a feature needs it, and you write just enough of a rule to stop the app breaking in testing. That's fine right up until a client can write more than you intended it to.
The mistake I made, in general terms, was trusting the client for things that should only ever be decided server-side: status flags, ownership, anything that changes what a user is allowed to do next. A rule that checks "is this user signed in" is not the same as a rule that checks "is this user allowed to write this specific field to this specific document." The gap between those two checks is exactly where problems live.
The core principle: never trust the client for anything that grants access
The rule I now hold myself to is simple: if a field determines what a user can do or see, the client must never be able to set it directly. It has to be set by trusted server-side code — a Cloud Function, for instance — that has already verified the change is legitimate. The Firestore rule's job then becomes making sure clients can't bypass that server-side path, not deciding business logic itself.
In practice that means splitting documents mentally into two categories: fields the owner can freely edit (their own task list, their own preferences) and fields that represent state the system controls (subscription status, permissions, anything tied to billing or access). The rules for the first category can be generous. The rules for the second category should default to "deny," with narrow, explicit exceptions.
Locking down field-level writes
Firestore's rules language supports checking exactly which fields a write is touching, not just whether the write is allowed at all. That's the tool that makes the split above enforceable rather than aspirational:
match /tasks/{taskId} {
allow create: if request.auth != null
&& request.resource.data.ownerId == request.auth.uid;
allow update: if request.auth != null
&& resource.data.ownerId == request.auth.uid
&& !request.resource.data.diff(resource.data).affectedKeys()
.hasAny(['ownerId', 'isPro']);
}
The shape here is the point, not the exact fields: a user can update their own document, but the rule explicitly blocks them from touching the fields that represent ownership or access level, even on documents they otherwise own. Those fields can only change through a path that isn't this rule at all.
Testing rules without a live attacker
You don't need someone trying to break in to find these gaps — you need to test the rules themselves as a first-class part of development, not an afterthought once something feels "done." The Firebase emulator suite lets you write rules tests that assert specific writes are denied, not just that the happy path is allowed. Writing a test for "a non-owner cannot update this document" is just as valuable as testing that the owner can.
I spotted the gap myself, and I wanted to make sure everything was completely ironclad.
What I'd do differently from day one
If I were starting again, I'd write the "server controls this field" list before writing the first rule, not after noticing a gap. It's a five-minute exercise — walk through every field in the schema and ask "could a malicious client benefit from setting this?" — and it catches the class of mistake that's easy to miss when you're focused on getting a feature working rather than thinking about what a hostile client could do with it.
The takeaway
Security rules should enforce a boundary that already exists in your server-side logic, not invent one on the fly in the rules file. Decide which fields represent trust and access, make sure only trusted code can set them, and then write rules that block everything else — and test that boundary directly rather than assuming it holds. It's a less exciting way to spend an afternoon than shipping a feature, but it's the difference between an app that's secure by design and one that's secure by luck.
The caching work in Turning an Assignment Brief Into a To-Do List With AI sits on top of the same principle — the client triggers the work, but never decides the result that gets trusted afterwards.