Authz security

From superagent-ai/skills · View interactive version

Authz security is an AI agent skill from the GitHub repository superagent-ai/skills. Review application source code for broken authorization — IDOR / Broken Object Level Authorization (OWASP API1), Broken Function Level Authorization (API5), mass assignment (API3), multi-tenant isolation gaps, and privilege escalation. Reads routes, controllers, resolvers, and data models offline an

How to use this skill

Skill file

Authorization Security Scanner

This skill turns the model into an authorization reviewer. Read the routes, controllers, resolvers, and data models; walk the detection passes; report each missing access-control check with a severity and a concrete, framework-correct fix. No tools to install, no app to run, no credentials — the analysis is the model reading the code.

Broken access control is the OWASP Top 10's #1 web risk (A01) and the top two API risks (API1 BOLA, API5 BFLA). It tops the lists precisely because automated tools miss it: there is no dangerous function call to grep for. The bug is the absence of a check, and confirming it requires understanding the application's ownership model — which is exactly what a model reading the code can do and a signature scanner cannot.

Mental model

Authentication answers who are you? Authorization answers are you allowed to do this, to this specific object? This skill is only about the second question. A handler can be perfectly authenticated and still be a critical vulnerability.

Every privileged operation can be escalated along two axes:

The defect is almost always missing code, not wrong code: a query that filters by object id but not by owner, an admin route guarded by "is logged in" but not "is admin," a body that binds straight to a model. So you are scanning for a gap, not a pattern.

When you cannot tell whether a check exists, assume it does not, and flag it for confirmation. The cost of a false positive is a review comment. The cost of a false negative is every user's data. This asymmetry governs every judgment call below.

Scan procedure

Walk these passes in order. Pass 0 builds the context the rest depend on — do not skip it.

Pass 0: map the ownership and tenancy model

You cannot tell that a check is missing until you know what "owning" an object means here. Before reading a single endpoint, read the data layer — ORM models, schema, migrations — and establish:

Write this map down (even informally). Every later finding is "principal P touched object O without confirming P may access O" — you need to know O's owner to make the call.

Pass 1: enumerate handlers and the objects they touch

List every entry point: REST routes, controller actions, GraphQL resolvers, RPC/gRPC methods, server actions. For each, record:

Flag every handler that loads or mutates an object by a client-supplied identifier — those are the BOLA candidates for Pass 2. A handler that only ever uses the principal's own id from the session (GET /me, current_user.orders) is low risk and can be deprioritized.

Pass 2: object-level authorization (BOLA / IDOR) — OWASP API1

For every handler flagged in Pass 1, ask: is there a check that the principal owns or may access this specific object? An acceptable check takes one of three forms:

  1. Owner-scoped query — the lookup itself includes the owner, so a non-owned id simply isn't found:

```python

invoice = Invoice.objects.get(id=id, org=request.user.org) # 404 on someone else's

```

  1. Explicit post-load check — load, then compare to the principal and reject:

```python

invoice = Invoice.objects.get(id=id)

if invoice.org_id != request.user.org_id:

raise PermissionDenied

```

  1. Centralized policy / ability — a guard that encodes the rule: authorize! :read, invoice (Pundit/CanCanCan), @PreAuthorize("hasPermission(#id,...)"), an OPA/Cedar/OpenFGA decision, a policy gate.

If the object is loaded by a client-supplied id with none of these — only the id, on the assumption that "you had to be logged in to get here" — that is the canonical IDOR. Authentication is not authorization.

// [P0] BOLA — Express: looks up by id, never checks ownership
app.get("/api/orders/:id", requireAuth, async (req, res) => {
  const order = await Order.findByPk(req.params.id);
  res.json(order);
});

// Fixed — scope to the authenticated principal
app.get("/api/orders/:id", requireAuth, async (req, res) => {
  const order = await Order.findOne({
    where: { id: req.params.id, userId: req.user.id },
  });
  if (!order) return res.sendStatus(404);
  res.json(order);
});

Severity: P0 for a sensitive read or any write/delete reachable by any authenticated user; P1 if the id space is large and unguessable and the data is low-sensitivity (still a finding — unguessable ids leak).

Pass 3: function-level authorization (BFLA / vertical) — OWASP API5

Endpoints that perform privileged actions — user management, role changes, admin dashboards, data exports, billing, internal tooling, feature flags — must check the principal's role or permission, not merely that they are authenticated.

Flag:

# [P1] BFLA — authenticated, but any user can promote anyone to admin
@router.post("/users/{id}/role")
def set_role(id: int, body: RoleIn, user=Depends(current_user)):
    User.objects.filter(id=id).update(role=body.role)

# Fixed — assert the privilege
@router.post("/users/{id}/role")
def set_role(id: int, body: RoleIn, user=Depends(current_user)):
    if not user.is_admin:
        raise HTTPException(403)
    User.objects.filter(id=id).update(role=body.role)

Pass 4: mass assignment / excessive property binding — OWASP API3

When a handler binds the whole request body to a model — User.update(req.body), Model(**request.data), user.update_attributes(params[:user]), Object.assign(entity, req.body) — ask which fields the client should not control: role, is_admin, is_verified, email_verified, owner_id, org_id, tenant_id, balance, price, status. If any reachable, the client escalates privilege or moves objects between tenants by adding a field.

Fix: allowlist the writable fields explicitly — strong params, a serializer/DTO with named fields, a Pydantic model scoped to inputs. Never bind a raw body to a persistence model.

Pass 5: trusting client-supplied identity

The principal — and the tenant — must be derived server-side from the session or a verified token, never from a client-controlled value. Flag any of these used for an authorization decision or query scoping:

// [P0] — scopes by a query param the caller controls
app.get("/api/invoices", requireAuth, async (req, res) => {
  res.json(await Invoice.findAll({ where: { userId: req.query.userId } }));
});
// Fixed: scope by the session principal, ignore client-supplied identity
//   where: { userId: req.user.id }

Pass 6: consistency and edge surfaces

Authorization bugs cluster where coverage is uneven. Check each:

Pass 7: indirect or non-controls

Things that resemble authorization but are not. Each of these, when it is the only thing between users, carries the same severity as the missing check it is standing in for:

Finding format

Report each finding in this structure. Group by severity, P0 first.

[P0] bola in app/controllers/orders_controller.rb:42
  #show loads Order by params[:id] with no ownership check. Any authenticated
  user can read any order by changing the id (sequential integers).
  Principal: current_user. Order belongs to a user via user_id.

  Vulnerable:
    def show
      @order = Order.find(params[:id])
    end

  Fix (scope the lookup to the owner; 404s on non-owned ids):
    def show
      @order = current_user.orders.find(params[:id])
    end

If the user pastes a snippet without a path, refer to "the handler" and use line numbers within the snippet. Always name the object, its owner, and the principal — that triad is the proof the check is missing.

Severity scale

When the code looks fine

After all passes, if nothing fires:

  1. Say so explicitly, and state what you verified: the ownership model from Pass 0, the handlers enumerated, and that every object-by-id path and privileged function carries a check across all verbs.
  2. Note what static review cannot confirm: runtime middleware wiring and ordering, the actual body of a centralized policy you didn't see, framework defaults, and whether deployed config matches the code.
  3. Recommend confirming at runtime with a dynamic BOLA test (two accounts, swap ids) against a running instance — the complementary offensive check this skill does not perform — and walking references/checklist.md.

A clean static read does not prove the deployment is safe.

Reference files

What this skill won't do

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.