Invental/Review lessons/Trust boundaries the server must hold

Trust boundaries the server must hold

Take audit scope from validated input

Take the scope of an audit decision from the authorisation check, or from validated input, never from raw request fields. Otherwise the person being audited can choose the settings that judge them.

01 · Before and afterThe pattern

TypeScript
// before: any request field may steer the scope
const projectId = ctx.project?.id ?? req.params.projectId ?? req.body?.projectId ?? req.query?.projectId;

// after: only fields the route actually validated
const { schema } = req.routeOptions;
const projectId = ctx.project?.id ?? req.params.projectId
  ?? (schema?.body ? req.body?.projectId : undefined)
  ?? (schema?.querystring ? req.query?.projectId : undefined);

02 · Run it on your appThe check

Can a user change whether their own failed action gets logged by adding a parameter to the request?

If the honest answer is no or not sure, this is worth a look before it reaches production.

Want this checked on your code?

Tell us what you are building and what worries you. We match a senior reviewer to your code and confirm scope before anything starts.

— Get in touch
hi@invental.co ↗
— Or
— What to include

A link or short description of the code or system, what you want checked, your stack, and when you need the answer. No repository access is needed until scope is agreed.

— Or leave a note
We reply within one business day.