Here is the kind of pull request that worries me. Four hundred lines. Services renamed, a helper moved, a typo fixed in an error message. Everyone reads it, someone leaves a nice comment about the typo, and it gets merged before lunch.
Somewhere in the middle of it, one line in the orders resource changed from owner | admin to authenticated. Now any signed-in user can read any order. Nobody noticed, because nobody was looking for it. Code review is good at catching typos. It is bad at catching a policy that got one word wider.
This is the last post in my CalmAPI 2 series, and it’s about the question I now ask every week: did my API get more permissive, and if it did, did a person say yes to that?
Why access changes hide in diffs
Access changes are small. That’s the whole problem. A policy is usually one word in a route file. Sometimes it lives in a config object far away from the handler. Sometimes it’s inherited from a base class or a middleware that someone “cleaned up”. The diff shows you lines, and a one-word change in a 400-line refactor looks exactly like the other 399 lines.
Add an AI agent to the team and it gets worse. Agents are happy to loosen a policy to make a failing test pass. They don’t do it to be evil. They do it because “the test was getting a 403” is a problem and “make the route less strict” is a solution. I wrote about giving agents a leash on your backend a few weeks ago, and this is the other half of that idea.
Make the access matrix something you can read
The fix starts with a boring idea. Write down who may do what, as data. Every route, every role, allow or deny. A table with routes down the side and personas across the top: anonymous, signed-in user, owner, admin.
Once that table exists as a file, an access change stops being a word buried in code. It becomes a cell that flipped from deny to allow. You can’t miss that in a diff. If you read my post on testing your API as every role, this is the same table, just committed instead of printed once and forgotten.
Snapshot it and diff it in CI
You don’t need any particular framework for this. The manual way is a small script that walks your routes, asks your auth layer what each role is allowed to do, writes JSON, and lets git do the comparing. The route walking part depends on your stack, so treat this as a shape, not a copy-paste:
// scripts/access-matrix.js
// listRoutes() and canAccess() are yours: wrap your router and your policy check
import { writeFileSync } from 'node:fs';
import { listRoutes, canAccess } from '../src/access.js';
const roles = ['anonymous', 'user', 'owner', 'admin'];
const matrix = {};
for (const route of listRoutes()) {
const key = `${route.method} ${route.path}`;
matrix[key] = Object.fromEntries(roles.map((r) => [r, canAccess(route, r)]));
}
writeFileSync('access.json', JSON.stringify(matrix, null, 2) + '\n');
# in CI, after checkout
node scripts/access-matrix.js
git diff --exit-code access.json # fails if anything changedThree rules make this actually work. Commit access.json. Fail the build when it changes. And when a change is intended, a human regenerates the file, commits it, and writes why in the commit message. That last part matters most. The reason is what your future self, or an auditor, will want to read.
One honest weakness: git diff --exit-code fails on every change, including ones that make access stricter. If that gets noisy, compare the two files in a few lines of code and only fail when a cell goes from deny to allow.
Access is not the only thing that drifts
Once I started thinking in snapshots, I saw the same pattern everywhere. A few other things quietly change between releases:
- Behavior since a git ref. New routes, fields visible to more people, new environment variables, new hosts the code calls. Compare against
main, not against your memory. - Invariants. Rules that must always hold, like “no public write routes” or “personal data is never public”. Write them once so nobody has to remember them.
- Budgets. A route that ran 3 queries last week and 40 today still passes its tests. Put a number on queries, p95 time and response size per route, and check it.
None of these need fancy tooling to start. A spreadsheet of invariants you check before a release is already better than nothing.
How CalmAPI does it
I built all of this into CalmAPI, the open source Node.js framework I’ve been writing about in this series. Version 2 is still in beta (2.0.0-beta.1 as I write this), so expect rough edges. You start a project with npm create calmapi@latest my-api, and it needs Node.js 22.12 or newer and MongoDB.
The exposure budget is the committed table from above. calm audit --accept writes the matrix to security.snapshot.json. After that, calm audit --ci and calm doctor --ci fail when access is wider than the file. Accepting wider access needs --reason, which is stored next to your name. And it refuses to run in an AI agent’s shell. Accepting is for a person.
The behavior diff compares two versions by what they do. This is the output example from the docs, shortened a little, and it’s exactly the pull request from the top of this post:
$ npx calm diff main Behavior changes since main (5) + POST /api/refunds policy: admin ~ GET /api/orders/:id policy: owner | admin -> authenticated looser ~ user.phone visible to: the owner and admins -> everyone looser, personal data + env STRIPE_SECRET_KEY required in production, secret + calls api.stripe.com reachable from the code 2 of 5 widen access.
calm diff --ci exits with 1 when a change widens access, and calm diff main --api does the same for your API contract, sorting changes into breaking, minor and patch.
calm review shows what changed since the last time a person signed, including files an agent changed that nobody has signed. calm review --sign writes a small file in .calm/reviews/ that you commit, and like accepting, it won’t run in an agent’s shell. Invariants live in calm.config.js and in production the app refuses to start if one is broken. Budgets sit in the same file:
// calm.config.js
export default defineConfig({
invariants: ['no public write routes', 'personal data is never public'],
budgets: {
'GET /api/posts': { queries: 1, p95: '150ms', response: '200kb' },
'*': { queries: 12, p95: '400ms' },
},
});
# CI
npx calm doctor --ci
npx calm review --ci
MONGODB_TEST_URI=mongodb://127.0.0.1:27017 npx calm audit --ci
MONGODB_TEST_URI=mongodb://127.0.0.1:27017 npx calm budgets --cicalm doctor --ci needs no database. The audit and budgets runs need MongoDB, since they run real requests and your tests. There’s also replay, which re-sends recorded requests after a change and tells you when a field is newly returned. Three checks, three angles: a committed list of who may do what, the last signed review, and a git ref.
The whole series, in one place
If you missed the earlier posts, here they are in order:
- I rewrote my own framework and deleted five of every six files
- Test your API as every role before someone else does
- Your framework shouldn’t be a black box in node_modules
- Let the AI agent touch your backend, but give it a leash
- Stop passing req.query straight into MongoDB
- The fields your API leaks without you noticing
The beta is open. If you try it and something breaks, or the docs say one thing and the CLI does another, please open an issue on GitHub. That’s the most useful thing anyone can do for it right now.
The habit
Treat “who can do what” as an artifact. Write it down, commit it, fail the build when it gets wider, and make a person say why. Do it with a twenty-line script, with CalmAPI, or with something else entirely. Use whatever you like, the habit matters more than the tool.
We do a lot of this kind of work in the open at Broadifi. You can see our open source projects here, or write to contact@broadifitech.com if you want a second pair of eyes on how access works in your API.

