#Why this matters
Modern web and mobile applications exchange structured JSON over REST endpoints or flexible queries over GraphQL rather than relying on server-rendered HTML forms. Because clients interact directly with backend data objects, APIs expose predictable endpoints, field names, and batch operations that are straightforward to inspect with curl, Postman, or Burp Suite.
The OWASP API Security Top 10 (2023) documents why traditional perimeter filters fail here: most critical API breaches do not involve SQL injection or broken TLS, but valid authenticated users accessing someone else's objects, overwriting restricted fields, or exhausting backend resolvers.
#Core authorization flaws in REST APIs
Three authorization failures sit near the top of the OWASP API Security Top 10 (2023):
| OWASP API Risk | What breaks | Concrete example |
|---|---|---|
| API1:2023 BOLA | Endpoint checks login token, not object ownership | GET /api/v2/invoices/1042 changed to 1043 returns another customer's bill |
| API3:2023 BOPLA | Missing per-property read or write checks | Response leaks password_hash, or PATCH with {"role":"admin"} elevates privileges |
| API5:2023 BFLA | Missing role check on privileged functions or methods | Standard user sends DELETE /api/v2/users/18 or hits /api/v2/admin/export |
Broken Object Level Authorization (BOLA), historically known as IDOR, occurs whenever a route trusts a client-supplied identifier (id, order_uuid, account_no) without scoping the database lookup to the caller's identity.
Broken Object Property Level Authorization (BOPLA) unifies two closely related bugs: excessive data exposure and mass assignment. In excessive data exposure, the backend serializes an entire database record (user.to_dict()) and expects the frontend mobile app to display only name and avatar, while the raw JSON leaks internal_flags or email. In mass assignment, the backend passes request.json directly into an ORM update call, letting an attacker append unrequested fields such as "is_verified": true or "credit_balance": 5000.
$ curl -s -X PATCH "http://lab.local/api/v2/profile" \
-H "Authorization: Bearer $USER_TOKEN" \
-H "Content-Type: application/json" \
-d '{"display_name":"Ali","role":"admin"}'
{"id":1042,"display_name":"Ali","role":"admin"}To prevent BOPLA, bind incoming payloads through an explicit allow-listed Data Transfer Object (DTO) or schema validator rather than raw ORM models:
ALLOWED_PROFILE_FIELDS = {"display_name", "timezone"}
def update_profile(current_user_id, body):
safe_updates = {k: v for k, v in body.items() if k in ALLOWED_PROFILE_FIELDS}
return db.users.update(where={"id": current_user_id}, values=safe_updates)#GraphQL architecture and attack surface
Unlike REST, where each resource has its own URL and HTTP verb, a GraphQL API typically exposes a single endpoint such as /graphql and lets the client specify exact fields, nested relations, and mutations in a POST body. That flexibility introduces distinct risks:
- Production introspection: Built-in introspection queries (
__schema,__type) return the full list of types, queries, and mutations (including undocumented admin operations) to anyone who asks. - Unrestricted Resource Consumption (API4:2023): Because schemas often link types bi-directionally (for example
UsertoOrganizationtoMemberstoOrganization), a deeply nested query forces exponential database joins. Similarly, GraphQL aliases or query batching let an attacker pack hundreds of login attempts (a1: login(...),a2: login(...)) into one HTTP POST, bypassing naive per-request rate limits. - Inconsistent authorization: Developers sometimes protect top-level REST-like queries while forgetting object-level checks on nested resolvers or mutations.
# Example introspection probe and nested resource-exhaustion pattern
query InspectSchema {
__schema {
types { name fields { name } }
}
}
query DeepNesting {
user(id: 1) {
team { members { team { members { email } } } }
}
}#Inventory, rate limits, and downstream APIs
Three additional OWASP API Security Top 10 (2023) categories frequently turn minor issues into breaches:
- API9:2023 Improper Inventory Management: Old versions (
/api/v1/), beta routes, or debug gateways remain reachable after/api/v2/launches with stronger authentication or DTO filtering. - API4:2023 Unrestricted Resource Consumption: Unbounded pagination (
?limit=100000), missing payload size limits, and absent per-user quotas allow scraping or denial of service. - API7:2023 SSRF and API10:2023 Unsafe Consumption of APIs: Webhook URLs supplied by users can trigger Server-Side Request Forgery against internal metadata services, while blindly trusting JSON returned from external partners can inject unexpected types or payloads into internal workflows.
#Defending REST and GraphQL APIs
- Enforce object ownership in the data layer: Derive
current_user_idstrictly from the verified session or JWT, and include ownership constraints inside every query (WHERE id = :id AND owner_id = :uid). - Use strict input and output schemas: Define separate DTOs for requests and responses. Reject or ignore unknown input keys, and never serialize raw database rows directly to JSON.
- Centralize function-level checks: Apply role and permission middleware by default on every route group, explicitly marking public routes instead of remembering to guard admin ones.
- Constrain GraphQL execution: Disable introspection in production, enforce maximum query depth and complexity/cost limits, restrict alias and batch counts, and perform authorization inside service-layer resolvers.
- Manage API lifecycle and quotas: Maintain a live OpenAPI/GraphQL catalog, decommission deprecated versions promptly, cap pagination limits, and validate outbound webhook URLs against private IP ranges.
#Common mistakes
- Hiding sensitive fields in the React or mobile client while still returning them in the API JSON payload.
- Applying HTTP rate limiting per request without accounting for GraphQL query batching or aliases inside a single POST.
- Using unpredictable UUIDs for object IDs as a substitute for BOLA authorization checks (UUIDs slow enumeration down, but leaked IDs in logs or URLs still expose data without ownership checks).
- Securing
/api/v2/while leaving/api/v1/or/internal/accessible on the same host.
#Summary
REST and GraphQL APIs concentrate risk in authorization, schema exposure, and resource limits as captured by the OWASP API Security Top 10 (2023). BOLA, BFLA, and BOPLA allow callers to read other users' records, call admin actions, or overwrite protected properties, while GraphQL introduces introspection leaks, nested query exhaustion, and alias-based rate-limit bypasses. Prevent these flaws by enforcing object ownership in backend queries, filtering both inputs and outputs through explicit schemas, bounding GraphQL depth and cost, and retiring obsolete API versions.