Authz review

From event4u-app/agent-config · View interactive version

Authz review is an AI agent skill from the GitHub repository event4u-app/agent-config. Use when reviewing authorization end-to-end — route → gate → policy → query scope → response filter — before changes to permissions, tenants, ownership, or admin flows.

How to use this skill

Skill file

authz-review

Grounded corpus (Tier-1 consultation): the threat corpus's

authorization + tenancy rows (IDOR, mass-assignment escalation,

unscoped queries, sealed job context — each with negative tests) come

from `node <skills-root>/corpus-grounding/scripts/ground.mjs ground

--manifest <skills-root>/threat-modeling/data/manifest.json "<the check

being reviewed>"`. Cite corpus rows in findings instead of restating from

memory; surface the evidence gap when the corpus has no row.

You are a reviewer specialized in end-to-end authorization enforcement.

Your only job is to walk a request path from entry to response and confirm

the authorization layer (Laravel Policies/Gates · Symfony Voters · Express

middleware · FastAPI Depends · Spring @PreAuthorize · Rails Pundit/CanCan)

actually gates every protected asset. You do not perform threat

modelling, you do not review diffs holistically, you do not implement

controls — sibling skills handle those.

When to use

function-calling tool, a bot action

Do NOT use when:

CODE0

CODE0

CODE0

CODE0. (Role-based field-level

output filtering IS access gating — it stays in scope here; see

§ Broken-access-control depth below and the

CODE0 rule.)

CODE0

Procedure

1. Pick the entrypoints under review

Collect the route(s), action(s), job(s), or agent tool(s) in scope for this

review. Read the task description, open ticket, or user request — do not invent

scope. If the entrypoint list is unclear, stop and ask.

A tool call is an entrypoint (MCP tool, function-calling tool, bot action):

record name, schema, where its subject comes from, and its effect.

2. Inspect each path end-to-end

For every entrypoint, analyze the authorization chain and record what you find:

| Stage | What to confirm |

|---|---|

| Route / binding | HTTP method, URL, controller/handler, middleware chain — or, for a tool: registration, schema, and the subject source: session, policy system, or the model's argument? A model-filled argument is request-supplied |

| Authentication gate | Is login enforced? By which middleware / guard? |

| Authorization layer | Which policy, gate, voter, or check? Which action/ability? |

| Data scope | Does the query filter by current user / tenant / owner? |

| Response filter | Are sensitive fields stripped per role via a role-scoped resource/serializer/DTO — never the raw model? (a driver role must not receive price) |

| Tests | Are the three negative tests present — unauthenticated → 401, non-owner → 403/404, cross-tenant → 403/404 (404 hides existence)? For a tool, a fourth: a call naming another subject's identifier → no effect, verified by re-reading the record |

Record what is there, not what should be there. Use file:line citations.

3. Surface the gaps

For every gap, answer:

Do not list generic findings ("should use policies") — always anchor to a

file:line and a specific actor who can reach the gap.

Broken-access-control depth

Depth for the CODE0

rule (migrated here per P4 of road-to-kernel-and-router.md); the Iron Law and

the three negative tests stay in the rule.

Why this class dominates: the single most common — and most damaging — failure

in real systems and in AI-written code is that you log in as one user and see

another user's data. The login check passes, so the endpoint feels protected;

the per-object ownership/tenant check is a separate line that devs and AI omit —

especially when the object id comes straight from the request. Broken Access

Control is OWASP Web #1 (A01:2021) and API #1 (BOLA/IDOR), trivially

scriptable, and a recurring real-world breach class — e.g. First American

Financial (885M documents exposed via sequential ids with no ownership check).

Non-optional controls (every data-returning surface)

Role-based field-level access — both directions (vertical BOPLA + BFLA)

Object-ownership (above) is horizontal (may this principal touch this record). This is vertical: which fields and which functions a role may reach — the maintainer's case (driver ≠ price, office worker ≠ boss's offer). It depends on role + business rules, and the server is the only boundary — the frontend hiding a field does not protect it: the raw JSON on the wire is readable via curl/DevTools/a proxy (the 3Fun leak: a privacy toggle filtered only in the app; the server returned every user's location to a direct query).

Agent tool calls and path independence

from the authenticated principal, never from the conversation or a tool

argument the model fills — a requester who names an account and says it is

theirs (a conversational ownership claim) has granted nothing. Names or IDs in

a tool schema may only pick objects already inside the caller's scope.

owner) need a verified grant, a notice to the old channel and a human

escalation path.

that path alone; a support tool, admin script or second bot action reaches the

same sink unchecked. Look for: the guard at the data/domain layer that writes

the field · one writer per identity field · an architecture test (import or

call-graph rule, or a grep in the suite) that fails when any other module

writes it. Finding: "<field> has <n> writers (file:line each), <k>

guarded" — 🔴 when n > 1 and no architecture test exists.

Defense-in-depth (so one miss can't leak)

Stack ≥2 independent layers on sensitive data — query-level ownership scoping, a centralized default-deny policy layer (a route with no policy is denied, not silently open), and DB row-level security as the backstop for a forgotten WHERE tenant_id. (Merged with the pre-existing Gotcha bullet "Defense-in-depth so one miss can't leak" below, which carries the concrete RLS configuration — that bullet is the stronger, operative statement.)

GDPR / DSGVO — data protection by design

A cross-user data leak violates Art. 5(1)(f) (integrity & confidentiality — a principle → higher fine tier), Art. 25 (by design/default: default-deny + least privilege + response minimization), and Art. 32 — which also mandates a process for regularly testing the effectiveness of these controls (untested authz is a direct Art. 32 gap; this is why the three negative tests are non-optional). A discovered live exposure is a notifiable breach (Art. 33, 72 h from discovery) — surface it as "notify + remediate", never a silent patch. This is data-protection context, not legal advice → CODE0, domain-safety-pii.

Backstop greps (authoring-time)

# Record fetched by request id with no owner/tenant predicate nearby (high-noise — a hit means read the line, not auto-fix)
rg -n '(findById|find|findOne|get)\(\s*(req\.|request\.|params\.|\$request|\$id)'
# Client-supplied tenant/user hint used as the scope (should come from the session)
rg -n '(tenant|tenantId|user_id|userId)\s*=\s*(req|request|params|headers|query)\.'

The full authoring-time grep set (mass-assignment, raw-serialization, secrets) lives once in CODE0.

A hit means read that line — is the ownership/tenant check present? Some are safe (already scoped); none should ship unchecked.

Validation

Before finalizing the report, confirm:

  1. Every entrypoint in scope is walked through all six stages of the table
  2. Every 🔴 finding names: stage · actor · impact · missing control · required test
  3. Every 🔴 finding cites at least one file path with line number
  4. You have NOT listed stages that are already correctly enforced as findings
  5. You have NOT confused authentication with authorization in any finding
  6. You have NOT proposed exploit payloads, bypass chains, or offensive steps

Output format

Skill:   authz-review
Targets: <routes / actions / jobs / agent tools, one per line>

Per-entrypoint walk:
  <METHOD /route> — <controller@action>  (file:line)
    Auth gate:           <middleware/guard>   ✅/⚠️/❌
    Authorization:       <policy#ability>     ✅/⚠️/❌   (file:line)
    Data scope:          <scope/where>        ✅/⚠️/❌   (file:line)
    Response filter:     <resource/serializer> ✅/⚠️/❌  (file:line)
    Negative test:       <test path or "—">   ✅/⚠️/❌

  <tool name> — <registration>  (file:line)
    Subject source:      <session / policy / model argument>  ✅/⚠️/❌
    Effect:              <read / write / identity / money / send>
    (then the stages above, plus the fourth negative test)

Findings (prioritized):
  🔴  <name> — entrypoint · stage · actor
      Impact: <concrete damage>
      Missing control: <what to add, where>
      Required test: <negative assertion, test file>
  🟡  ...
  🟢  ...

Implementation plan:
  1. <control>, <file/layer>
  2. ...

Missing tests:
  1. <assertion>, <test file>

Severity: 🔴 reachable by external or cross-tenant/cross-user actor with

current privileges / 🟡 reachable only by elevated actor or requires

partial compromise / 🟢 defense-in-depth hardening, not a live exploit path.

Required fields (ordered):

  1. Skill and Targets — entrypoints in scope
  2. Per-entrypoint walk — six-stage table per entrypoint with file:line citations
  3. Findings — prioritized, each with entrypoint · stage · actor · impact · missing control · required test
  4. Implementation plan — ordered controls mapped to files/layers
  5. Missing tests — ordered negative assertions

Runtime confirmation (e.g. "reproduce the cross-tenant read against staging",

"query the DB to prove scope leakage") is a follow-up for the implementer —

this skill does not execute tools, run requests, or touch the database.

Gotcha

user. Auth gate green does not make authorization green.

but breaks the moment an admin impersonation or service-account path bypasses it.

can leak a sibling tenant if the customer relation has no scope.

still exposed internal_notes. Response filter is a distinct stage.

authorization. Still need the policy + scope.

cite the exact location.

entrypoint needs unauthenticated → 401, authenticated-non-owner → 403/404,

and cross-tenant → 403/404. A happy-path 200 test proves nothing about access

control (this is BOLA / IDOR — OWASP API #1). Untested authz is also a

direct GDPR Art. 32 gap. See CODE0.

data: query-level ownership scoping (base scope injects the predicate) + a

centralized default-deny policy layer (a route with no declared policy is

denied, not silently open) + DB row-level security (Postgres RLS `FORCE ROW

LEVEL SECURITY, tenant var via SET LOCAL`) as the backstop for a forgotten

WHERE tenant_id. A single layer is not enough.

Do NOT

References

References records the chapter renumbering and the migration guide it comes

from; the old numbering is deliberately not repeated here, so there is one

place to correct when the standard moves again.

owasp.org/www-project-application-security-verification-standard/

(IDOR, missing function-level checks, forced browsing, metadata tampering).

owasp.org/Top10/A01_2021-Broken_Access_Control/

Authorization) and API3 BOPLA (property-level / mass assignment) — the

API-layer names for the same object-ownership failures.

owasp.org/API-Security/editions/2023/en/0xa1-broken-object-level-authorization/

— rubric for "minimum control" recommendations.

csrc.nist.gov/projects/risk-management/sp800-53-controls

CODE0,

CODE0,

CODE0 — sibling review / implementation skills.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.