Skip to content
← Journal
Engineering12 August 20268 min read

Trust boundaries are enforced everywhere, or nowhere

I audited all six repositories of a product I had helped build. The bugs were not exotic. They were the same idea, checked in one place and assumed in four others.

DraftThis piece is a researched draft awaiting a final pass. Facts are sourced at the bottom; the framing and opinions are still being edited.

iléSure is a student-housing marketplace: a backend, a React Native app, and four web front-ends. Agents list properties, students book and pay in Naira, identities get verified, tenancy agreements get signed. Real money, real identity documents, real consequences for getting it wrong.

I read all six repositories end to end and wrote up every finding against a file and line reference. I expected to find clever bugs. What I actually found was one idea, repeated.

The system got the hard things right

Credit where it is due, because it matters for the argument. Payment amounts were computed server-side in every wired flow, so no client could tamper with what it owed. The payment webhook preserved the raw body so the HMAC actually verified. Ownership checks on listings, bookings and chats were mostly present. There was no mass assignment on create or update.

Those are the things teams usually get wrong. This team got them right, which is exactly why the pattern underneath was worth naming.

The pattern: enforced once, assumed thereafter

Every serious finding was a trust boundary that existed in one place and was taken on faith everywhere else.

  • The auth middleware rejected admin-typed tokens but nothing else, so a 30-day refresh token worked as a bearer on every non-role-gated endpoint, quietly defeating logout and rotation
  • Identity verification succeeded, but the result was not bound to the caller who requested it
  • The admin console's gate was a client-side boolean; the server did not re-ask
  • Private chat threads rode along inside public listing responses, because the listing serializer was written before chats existed
  • Two shared-booking flows split the money wrong: the landlord was paid twice and the platform nothing

Read that list again and notice that none of them require an attacker to be clever. They require an attacker to try the second door after finding the first one locked.

Why this happens to good teams

Because the first implementation of a rule is a decision, and every implementation after it is a memory. You write the ownership check on the booking endpoint while you are thinking hard about ownership. Six weeks later you add the shared-booking endpoint while you are thinking hard about roommates, and the check is something you already did.

“A boundary enforced in one place is not a boundary. It is a convention with good intentions.”

What actually helps

Not more code review. Review is where this class of bug hides best, because each diff looks reasonable on its own. What helps is making the rule impossible to forget rather than easy to remember.

ts
// Not this: the check is a thing you must remember to write
router.post("/bookings/:id/pay", auth, async (req, res) => {
  const booking = await Booking.findById(req.params.id);
  if (booking.userId !== req.user.id) return res.sendStatus(403);
  // …
});

// This: the check is a thing you must deliberately opt out of
router.post(
  "/bookings/:id/pay",
  auth({ tokenType: "access" }),        // refresh tokens cannot reach here
  owns(Booking, "id"),                   // ownership is a route-level fact
  async (req, res) => { /* … */ }
);

Same for serialization: a listing should not be able to return a chat thread because the model cannot reach one, not because this particular query remembered to exclude it. And token type should be a first-class claim the middleware asserts, not something inferred from what it is not.

The part I would tell a younger version of myself

Auditing your own system is uncomfortable and it is the fastest learning I have done. Reading six repositories with no intention of fixing anything, just recording with file and line what is actually true, surfaces things that months of feature work never will. The report was more valuable than any single fix in it.