The RBAC that wasn't there
How placeholder middleware bypassed permissions platform-wide at Shofar.ai - and the four-move rebuild that enforced them.
In November 2025 I took over the auth service at Shofar.ai, a system made of ten-plus microservices. My first job was meant to be small: tighten up the permission layer. It wasn't small, because there was no permission layer.
What we found
The role middleware was a file with the right name and the right logs. Inside:
// auth/middleware/requireRole.js - as found (simplified)
function requireRole(role) {
return (req, res, next) => {
// TODO: enforce against user service
next();
};
}
It looked like a guard and logged like a guard, but it guarded nothing. Every route behind it was open to anyone with a valid login.
How a stub survives code review
The service was scaffolded with AI tooling early on, and the middleware came with that scaffold: named correctly, plausible, and empty. Nothing tested that the check existed, so no code review ever showed it missing. The tool wasn't the problem. The missing test was. Nothing in the suite expected a 403.
The second hole
Where checks did exist, they asked the wrong source. Controllers read the role from the dashboard's variables, which is state built for the UI, instead of the user's real role:
// orders/controller.js - as found (simplified)
if (dashboardVars.role === 'admin') {
// approve refund
}
So client-side state was deciding server-side permissions. Change what the dashboard shows and you change what you're allowed to do.
The rebuild, in four moves
The user service became the only source of truth for roles. Not the session, not the dashboard, not a cached copy in three services. One service gives the answer.
On every request, the middleware checks the token against the user service, with a short-lived cache so it stays fast under load.
// auth/middleware/requireRole.js - rebuilt (simplified)
function requireRole(role) {
return async (req, res, next) => {
const user = await usersService.byToken(req.auth.token); // source of truth
if (!user || !user.roles.includes(role)) {
return res.status(403).json({ error: 'forbidden' }); // fail closed
}
req.user = user;
next();
};
}
The check sits where requests enter each service. In Go, I wired the guard into the router so it runs before any business logic, not buried somewhere inside it.
Tests that expect denial. A suite logs in as a normal user and expects a 403 on every admin route, in CI, on every commit. This is the one that keeps it fixed.
The receipt
All ten-plus services now ask the user service and nobody else. The idea: same resource, two roles, one 403 and one 200. try /rbac-demo/admin?role=user, then swap the role.
Check your own MVP tonight
- Grep your middleware for a next() with no condition above it.
- In every permission check, who supplies the role - the token, or something the client can touch?
- Is there a single test in the suite that expects 403?
- Where does the check sit - at the edge of the service, or buried in a handler?
- When the user service is unreachable, does your check fail closed or fail open?
If any answer scares you, that is the email to send me.