security-hardeninglisted
Install: claude install-skill manishdashsharma/express-backend-skills
# Security Hardening
Work through each section against the code in scope. Fix what is fixable; list what needs a human decision.
## 1. Tenant isolation (most common real bug)
- Every domain query filters by the scope field taken from `req.user` / resolved middleware — **never** from `req.body` or `req.query`.
- Lookups by id include the scope: `findOne({ _id, storeId })` / `findFirst({ where: { id, orgId } })`. Id-only lookups are an IDOR.
- Another tenant's resource → **404**, so existence is not confirmed. Same for non-members of an org/project.
- Updates/deletes use scoped filters (`updateMany({ where: { id, orgId } })`) so a guessed id cannot touch another tenant.
- List endpoints for non-admin roles filter to what the caller may see, not "everything in the org".
- Public/share endpoints return an explicit allowlist of fields; never owner email, ids of private records or settings.
## 2. Input
- Every route has `validateRequest(schema, source)` for body, query **and** params. Zod strips unknown keys by default — keep it that way; never spread `req.body` into a write without a schema.
- Strings have `max()`; arrays have `max()`; numbers have bounds; ids have a format.
- Mass-assignment: fields like `role`, `isActive`, `storeId`, `plan`, `ownerId` are never accepted from clients on ordinary endpoints.
- User text used in `$regex` is escaped; Mongo filters never take raw objects from the client (operator injection: `{ "$gt": "" }`).
- Size limits at the edge: `express.js