A collections platform handling debt data in a regulated market (Brazil's LGPD)
cannot leak across tenants. An audit identified paths that needed stronger
ownership checks. This work addressed them with reusable guards rather than
one-off patches.
The platform is multi-tenant: creditors and operators share a deployment,
isolated by company domain. The data is sensitive — names, documents, debt
amounts. The risks included cross-tenant access (IDOR) and a weak identity check
that could be brute-forced in conversation.
Cross-tenant IDOR. Several endpoints took an entity ID and acted on it
without checking it belonged to the caller's tenant. An operator who learned
another tenant's identifier could read protected data or disrupt that tenant's
automation. Under LGPD, that is not just a bug — it is regulatory exposure.
Mass-assignment. An update path blindly copied request fields onto the
record, allowing writes to fields that should never be client-controlled.
Identity brute-force. The in-conversation identity check compared too few
digits with no rate limit, making it feasible to guess.
The common flaw was relying on endpoint-level vigilance. Ownership, writable
fields and identity strength were being rediscovered in separate code paths,
which made the protection inconsistent and easy to omit.
Tenancy guard
↔
A reusable guard checks tenant ownership at the application layer and records blocked attempts.
Instead of patching each endpoint, I added a helper that asserts the entity's
tenant matches the caller's, and applied it to the paths in scope. Blocked
cross-tenant attempts return an authorization error and can be logged as a
security event, creating an LGPD-useful audit trail. The helper gives new
endpoints a reusable ownership check instead of relying on repeated local logic.
The mass-assignment path was replaced with an explicit field allow-list. The
identity check was hardened to compare the full document with a constant-time
comparison, rate limiting, and lockout after repeated failures. The case keeps
the protection qualitative while factual review remains pending.
The login path got rate limiting and uniform error messages to kill account
enumeration, and a seed credential that had lived in source control was moved
behind a secrets manager.
Security in a multi-tenant product is mostly about invariants you can enforce in
shared paths. Reusable guards reduce the need to remember ownership checks in
each endpoint as the codebase grows.