Skip to content

API Threat Modeling REST GraphQL gRPC and Webhooks

github-actions[bot] edited this page Nov 29, 2026 · 1 revision

Last reviewed: 2026-11-28

Caution

Authorized use only. The verification steps in this guide send hostile requests. Run them only against your own code, a local lab such as labs/secure-api, or systems you have written permission to test. See LEGAL.md.

Prerequisites: Web application testing methodology ยท Glossary for API, BOLA, SSRF and related acronyms.

๐ŸŽฏ Purpose

Give developers one repeatable way to draw the trust boundaries of an API and list the threats at each boundary for REST, GraphQL, gRPC and inbound webhooks. Each threat is mapped to the OWASP API Security Top 10 2023 and to the guide in this folder that covers the control.

โš™๏ธ Function

Defines the trust boundaries common to most APIs. Lists threats per interface style, with the API Top 10 2023 category for each. Points each threat to the control guide and, where one exists, to the Secure API lab case that shows the flaw and the fix side by side.

๐Ÿ† Goal

A threat model that names every entry point, the identity and authorization decision made there, and the test that proves the decision. The aim is that no route, resolver, RPC method or webhook handler ships without an owner, a policy and a negative test.

๐Ÿ“‹ When To Use

  • Designing a new API, or adding a GraphQL, gRPC or webhook interface to an existing one
  • Reviewing a pull request that adds routes, fields, RPC methods or third-party callbacks
  • Preparing the scope for an authorized API assessment
  • Planning which negative tests a CI pipeline must run

๐Ÿ“‹ Table Of Contents

Trust Boundaries

Every arrow that crosses a dashed box below is a place where input is untrusted and an identity and authorization decision is needed.

flowchart LR
  subgraph internet["Untrusted: internet"]
    browser["Browser / SPA"]
    mobile["Mobile or CLI client"]
    sender["Webhook sender<br/>(payments, VCS, SaaS)"]
  end
  subgraph edge["Edge"]
    gw["API gateway / load balancer<br/>TLS, coarse rate limits, size caps"]
  end
  subgraph app["Application trust zone"]
    rest["REST handlers"]
    gql["GraphQL resolvers"]
    grpc["gRPC services"]
    hook["Webhook receiver"]
    policy["Central authorization policy"]
  end
  subgraph deps["Dependencies"]
    db[("Database / object store")]
    idp["Authorization server / IdP"]
    third["Third-party APIs"]
  end
  browser --> gw
  mobile --> gw
  sender --> gw
  gw --> rest & gql & grpc & hook
  rest & gql & grpc --> policy
  policy --> db
  rest -. "token validation keys" .-> idp
  hook --> db
  rest --> third
Loading
Boundary What crosses it Decision required at the boundary
Client to edge Credentials, tokens, request bodies, uploads TLS, body size and rate limits, authentication
Edge to handler Parsed request with a claimed identity Token or session validation, then per-object, per-function and per-property authorization
Handler to data store Queries built from request values Parameterized queries, tenant scoping, ownership filters
Sender to webhook receiver A signed event from a third party Signature over the raw body, timestamp tolerance, replay detection, then re-fetch or validate the state
Application to third-party API Data your code did not produce Validate responses as untrusted input, timeouts, egress allowlists (API10:2023)
Application to authorization server Codes, tokens, keys Exact redirect URIs, PKCE, state or nonce, issuer and audience checks

Modeling Steps

  1. Inventory every entry point. List each REST route and method, GraphQL type and field with a resolver, gRPC service and method, and webhook URL. Include versions, beta hosts and internal-only routes (API9:2023 Improper Inventory Management). Generate the list from code or the router where possible, and compare it with the published OpenAPI document, schema or .proto files.
  2. Name the caller and credential for each entry point: anonymous, session cookie, OAuth access token, mTLS client certificate, or webhook signature.
  3. Write the authorization rule for each entry point and each object it returns: who may call the function, which objects the caller may see, and which properties the caller may read or write. Put the rules in one policy module (API authorization).
  4. Record resource limits: body size, page size, query depth or cost, message size, rate per caller, and timeouts (rate limiting & resource exhaustion).
  5. Mark every parser: JSON, XML, multipart, archives, images and protobuf (file upload & parser boundaries).
  6. Decide the failure mode: what the endpoint does when the policy service, database or IdP is unavailable. The default answer is to deny (secure error handling).
  7. Write one negative test per threat and run it in CI. A threat without a test is an assumption.

Threats by Interface Style

REST

Threat Example API Top 10 2023 Control guide
Object ID swap GET /api/invoices/7 returns another user's invoice API1 API authorization
Admin route reachable by users POST /api/admin/users/2/disable works for any token API5 API authorization
Mass assignment / over-exposure PATCH /api/users/me {"role":"admin"} is stored; profile returns password_hash API3 API authorization
Weak token handling alg: none accepted, wrong aud accepted API2 OAuth & OIDC implementation
Unbounded requests ?limit=100000, 1 MiB bodies, unthrottled search API4 Rate limiting
Server-side fetch of user URLs Avatar-from-URL fetches cloud metadata API7 Cloud IMDS & SSRF
Verbose errors Stack trace in a 500 response API8 Secure error handling

GraphQL

GraphQL puts many objects behind one URL, so route-level checks are not enough. Authorization belongs in each resolver or in the data layer it calls, and cost limits apply to the whole document.

Threat API Top 10 2023 Control
Resolver returns objects without an ownership check API1 Same policy call as REST, inside the resolver
Deep nesting, many aliases, large batches API4 Depth, alias and token limits; cost analysis (webhooks, GraphQL & gRPC)
Alias or batch brute force of a login or OTP mutation API2, API6 Per-object rate limits in business logic, no batching for sensitive operations
Introspection and field suggestions in production API8 NoSchemaIntrospectionCustomRule, hide_suggestions=True

gRPC

Threat API Top 10 2023 Control
Plaintext channel, or tokens sent without TLS API2, API8 grpc.ssl_server_credentials, call credentials only over a secure channel
Method callable by any authenticated peer API5 A server interceptor that checks the method name against a policy
Reflection service exposed publicly API8, API9 Do not register reflection on public servers
Oversized messages, unbounded concurrency API4 grpc.max_receive_message_length, maximum_concurrent_rpcs, deadlines

Inbound Webhooks

Threat API Top 10 2023 Control
Forged event (no or weak signature check) API10 HMAC over the raw body, constant-time compare
Replayed event API10 Timestamp tolerance and a store of delivery IDs
Trusting event content for state changes API10 Treat the payload as a hint; re-read the object from the provider's API where it matters

OWASP API Security Top 10 2023 Mapping

The category names below are copied from the 2023 edition, which is still the current edition as of the review date. The lab column names the Secure API lab cases that show the flaw and the fix. A dash means the lab has no case for it.

Category Guide in this folder Lab cases
API1:2023 Broken Object Level Authorization API authorization bola-read-other-user-record
API2:2023 Broken Authentication OAuth & OIDC, sessions & tokens oidc-id-token-*, oauth-*, session-*, refresh-token-rotation-reuse
API3:2023 Broken Object Property Level Authorization API authorization bopla-mass-assignment, bopla-excessive-data-exposure
API4:2023 Unrestricted Resource Consumption Rate limiting, uploads & parsers rate-limit-429-retry-after, max-page-size, max-body-size, archive-decompression-bomb, graphql-depth-limit, graphql-alias-limit
API5:2023 Broken Function Level Authorization API authorization bfla-admin-route
API6:2023 Unrestricted Access to Sensitive Business Flows Rate limiting -
API7:2023 Server Side Request Forgery Cloud IMDS & SSRF -
API8:2023 Security Misconfiguration Error handling, GraphQL & gRPC graphql-introspection-disabled, error-problem-details-no-stacktrace, session-cookie-attributes
API9:2023 Improper Inventory Management This guide, Modeling Steps -
API10:2023 Unsafe Consumption of APIs Webhooks webhook-*

Verification Tests

For each entry point in the inventory, the minimum test set is:

Test Pass condition
No credential 401 with WWW-Authenticate for bearer APIs (RFC 6750 ยง3)
Valid credential, other user's object 404 or 403, and the object is unchanged after a write attempt
Valid credential, wrong role 403 on every admin function
Extra or read-only property in the body 400, and the stored value is unchanged
Over-limit body, page, depth or rate 413, a capped page, 400 or 429 as documented
Dependency failure The request is denied (for example 503), never served

The lab's runner is a working example of this pattern. Each check returns flaw_detected and sanity_ok, and a case only passes if the vulnerable twin shows the flaw, the fixed twin does not, and a legitimate request works on both. Mirror that in your own tests: always pair a negative test with a positive one, so a route that rejects everything does not pass by accident.

What the Lab Does & Does Not Show

The Secure API lab passed 67 of 67 cases in CI run 46241150192. That shows each check told one planted flaw apart from one fix in synthetic, illustrative teaching code on loopback. It is not an assessment of any framework or production system. The lab has no gRPC service and no SSRF, business-flow (API6) or inventory (API9) cases.

๐Ÿ“š References

See also

Related Files


โฌ…๏ธ Web Application Security index | Master Index | ๐ŸŽฏ Role Navigation | Legal Notice


๐Ÿ“„ Source: WebAppSecurity/api-threat-modeling.md | โœ๏ธ Suggest an edit | โฌ…๏ธ Back to Web App Security

Clone this wiki locally