Security

Object-level authorization

Object-level authorization checks whether a principal may act on a specific record. In a multi-tenant inventory API, both the tenant and the resource owner can matter. A valid identifier is only a way to locate a record; it is not permission to read or change it. Do not check only the owner ID when IDs can overlap across tenants. Do not trust tenant fields supplied by the requester. Do not fetch a record and serialize it before authorizing access. Evidence: local teaching fixture, not a production security guarantee. Source: https://cheatsheetseries.owasp.org/cheatsheets/Authorization_Cheat_Sheet.html

Formal Syntax & Structure

nodejs syntaxnodejs
SELECT title FROM books WHERE tenant=? AND id=? AND owner=?

Working Example

Example Snippetnodejs
function canRead(principal, book) {  return Boolean(principal && book &&    principal.tenant === book.tenant && principal.id === book.owner);}const book = {tenant:'north',owner:'u1'};for (const p of [null,{tenant:'north',id:'u1'}, {tenant:'north',id:'u2'},{tenant:'south',id:'u1'}]) {  console.log(canRead(p,book));}
Node.js Reference