HomeRulesBND012
BND012 · High severity

SECURITY DEFINER function is executable by API roles.

Revoking PUBLIC is only the first privilege boundary. A later direct grant to anon or authenticated still places an owner-privileged function on the client-facing RPC surface.

Detection condition

The rule reports a SECURITY DEFINER overload in a configured exposed schema when final execution privileges exclude PUBLIC but still include anon or authenticated. Function signatures, replacements, object grants and revokes, schema-wide grants, and default privileges are evaluated in order.

Why it matters

The caller enters code running with the function owner's privileges. Missing tenant correlation, overly broad parameters, or unsafe dynamic SQL can turn the RPC into a cross-tenant read or write path.

Typical remediation

Revoke direct API-role execution and grant the exact overload only to a trusted server role. If clients need the operation, expose a narrow wrapper that validates identity, membership, tenant correlation, and every writable field.

Restrict the exact overloadsql
revoke execute on function public.client_admin_lookup(uuid)
  from anon, authenticated;
grant execute on function public.client_admin_lookup(uuid)
  to service_role;
Protect the boundary

Make tenant isolation a repeatable pull-request check.

Run the deterministic scanner locally without database credentials, then add Cloud only when your team needs shared history.

Find client-executable privileged RPCs Read the quickstart