How to review authorization in AI-generated code
Use a permission matrix to review identity, resource ownership, allowed actions, and failure cases in AI-generated code.
Start with a permission matrix
Imagine a notes app where user A, user B, and a signed-out visitor request to read or change A’s private note. Write down the expected result for each combination: A may access their own note; B and the visitor may not read or change it. Add admin or sharing rules only if the product actually supports them.
Trace four questions
Where is identity verified? Who owns the note? Is this action allowed? What happens when the resource, identity, or authorization service is unavailable? A hidden button, random identifier, or model explanation is not an authorization check. Trace the server-side decision for the specific resource.
Test with counterexamples
At minimum, test that the owner can read and write, another user is denied both, a signed-out request is denied, and a missing note is handled. Check that listing, export, update, and deletion enforce the same resource-level rules. HTTP status codes depend on the product; a denied request must not expose or change private data.
A useful follow-up prompt
“Using this permission matrix, list missing server-side checks and counterexample tests. Make the smallest necessary change and explain where identity comes from and where each check runs. Do not equate hidden buttons with authorization or claim tests were run unless they were.” Review the diff and run the tests in an isolated environment.
Reference:OWASP Authorization Cheat Sheet