One missed account boundary can put a renewal at risk
Imagine a user exporting a report before a renewal meeting and finding another account’s records. That could put customer trust, retention, and an enterprise sale at risk. Here is how to keep every request inside the right account.
I worked on a multi-tenant SaaS: one product serving multiple customer accounts.
A request from the browser included the account it wanted to access. Several checks were already in place; my responsibility was to avoid weakening them or the separation between accounts.
The lesson is simple: the account ID in a request identifies what the user is asking for. It does not, by itself, prove they can access it.
If that boundary is weak, a routine feature—report export, admin view, background job—can become a customer-trust incident at the worst possible moment.
Keep each account’s data within its boundary
The way customer data is stored can vary.
Some products keep accounts in shared tables with an account ID on each record; others use a separate schema or database for each account, or combine these approaches.
Whichever model a team chooses, the application still needs to verify the user’s access and keep each operation within the selected account. Storage separation alone does not establish who may access an account.
For a request to view a report, a team can ask:
- Is the requested account recognized and available?
- Is this user allowed to act in that account?
- Is this user allowed to perform this action, such as viewing or exporting the report?
- Does the data operation only retrieve or change records belonging to that account?
These checks answer different questions. Account access does not grant access to every feature or every subset of data: a user may be allowed to view some account data but not use reports. And an access check does not constrain a query unless the query is also scoped to that account.
TypeScript: make the checks and data scope explicit
This example shows the flow directly. The membership lookup verifies the user’s account access; the permission check verifies the requested action; the final query uses that verified account. The repository methods stand in for the application’s data layer:
// Verify that the user can act in the requested account.
const accountAccess = await memberships.findOne({
where: {
userId: user.id,
accountId: requestedAccountId,
},
});
if (!accountAccess) return forbidden();
// Verify that the user's account role permits this action.
if (!can(accountAccess.role, "report:read")) return forbidden();
// Keep the report lookup within the verified account.
const report = await reportRepository.findOne({
where: {
id: requestedReportId,
accountId: accountAccess.accountId,
},
});
The account lookup does not replace the action permission, and neither one replaces the account filter on the data query. The same boundary needs to hold for updates, deletes, exports, and background work that handles customer records.
NestJS with TypeScript: keep the same boundary across a route
NestJS can apply the application’s authentication guard before the route runs. The service still checks account access and the action permission, then scopes the data query:
// The authentication guard establishes the signed-in user.
@UseGuards(AuthGuard)
@Get(":reportId")
getReport(
@Req() request: AuthenticatedRequest,
@Param("reportId") reportId: string,
@Query("accountId") accountId: string,
) {
return this.reports.getForAccount(request.user.id, accountId, reportId);
}
async getForAccount(userId: string, accountId: string, reportId: string) {
// Confirm the user can act in the requested account.
const access = await this.memberships.findOne({
where: { userId, accountId },
});
if (!access) throw new ForbiddenException();
// Confirm the user's role permits reading reports.
if (!can(access.role, "report:read")) throw new ForbiddenException();
// Restrict the report lookup to the verified account.
return this.reportsRepository.findOne({
where: { id: reportId, accountId: access.accountId },
});
}
The authentication guard establishes the signed-in user. The service checks whether that user can act in the requested account and read reports, then limits the report lookup to the same account. A team can place these checks in different layers, but each responsibility needs a clear enforcement point.
OWASP’s Multi-Tenant Security Cheat Sheet and Authorization Cheat Sheet offer further guidance on tenant isolation and authorization checks.
Make the account boundary reviewable
In a multi-tenant SaaS, keeping one customer’s data inside its account is part of protecting the product’s reliability and customer trust. But “we check the account” is not enough. The boundary needs to be visible in the code, in the tests, and in the paths teams forget about.
A focused account-boundary review should answer:
- Which account is this request for, and where is that account verified?
- Which action is being performed, and where is permission checked?
- Does every query, update, delete, export, and background job carry the verified account scope?
- Are there paths—admin tools, support views, async jobs—that bypass the normal route?
- Can the team point to the enforcement point in code and tests?
I help SaaS teams trace account access from request to data operation, identify where the boundary is enforced—or assumed—and strengthen it before it becomes a customer-facing incident. A review can be scoped to one feature, one launch, or one enterprise deal’s security questionnaire.
If your product serves multiple customers and you want a second set of eyes on account isolation, book an account-boundary review or reply with the part of the flow you’re least sure about.