Roles & Access Control
The Interface Is Not the Boundary — the Rules Are
Section 2 of 4
The client in this application holds a Firebase session and queries the database directly. There is no server in the middle deciding which documents a request is allowed to touch. That means authorization is not a feature of the interface — it is a property of the security rules, which run server-side on every operation and are the only thing standing between a valid session and every document in the project.
The right way to reason about this is to assume the interface does not exist. A signed-in agent can attempt to read any complaint, assign any job to themselves, or write to any user profile, because nothing stops them from issuing that query by hand. Every rule below is written against that assumption rather than against what the dashboards happen to offer.
3
roles, one carrying a trade category
4
independent grounds to read a complaint
5
failed attempts before rate limiting
0
authorization decisions made client-side
Reading a Complaint
The most involved rule in the project. Four independent grounds for access, evaluated server-side against the document being requested — not against anything the client claims about itself.
The pool model means an unassigned job is deliberately visible and writable by a group of agents rather than one. Granting that is the easy half. The hard half is granting it narrowly enough that the permission cannot be turned into something else.
A first pass would say: an agent may update a complaint that is in the pool for their category. That is enough to let them claim it — and also enough to let them assign it to a different agent, or take a job from the pool and write someone else's identifier into the assigned field, which is a way to dump work rather than accept it.
So the claim path carries an additional condition on the incoming data, not just the stored document: the assigned agent identifier in the update being written must equal the session's own identifier. An agent may claim from their pool, and the only person they may claim it for is themselves.
That distinction — between what the existing document says and what the proposed write contains — is the part of rule-writing that is easy to miss, because most conditions naturally read against the stored record. Any rule permitting a state change has to constrain the destination as well as the origin.
Team Access and the Hardening Pass
Managers and agents reach their dashboards through a team login gated by a shared password per role. The original private version compared that password in client-side JavaScript, which is a common shortcut and an unambiguous vulnerability: a value compared in the browser is a value present in the bundle, and anyone can read it without attacking anything.
The public version moves that check into a server route. The expected values are held in environment variables deliberately without the public prefix, so the framework excludes them from the client bundle entirely, and the browser only ever receives a boolean. The secret is never transmitted to the client under any code path.
The route also rate limits by forwarded client address, allowing a handful of attempts per window before returning a refusal — because a server-side check on a short shared password is still brute-forceable if it can be called without limit.
The rate limiter is in-process, which means it resets on cold start and is per-instance, so it degrades under horizontal scaling. That limitation is written down in the code itself rather than left for a reader to discover, along with what it should become — a shared store — if the deployment ever scales out. A known and documented limitation is a different thing from an unknown one, and I would rather ship the honest version than imply a guarantee the implementation does not make.