Index-based pagination retrieves a collection in smaller chunks by specifying how many items to skip and how many to return. section 6.1
It becomes a security concern when pagination parameters accept unbounded values. A request for 100 million products can pressure the database, and many concurrent requests can cause denial of service. section 6.1
A safer products endpoint
GET /products?page=5&perPage=10 requests a manageable slice. Define page with minimum 1 and maximum 100, and perPage with minimum 10 and maximum 100; document defaults rather than relying on presumed sensible values. section 6.1
Listing 6.2 Secure pagination
# file: ch06/6_1_safe_pagination.yaml
paths:
/products:
get:
parameters:
- name: page
in: query
required: false
schema:
type: integer
minimum: 1
maximum: 100
- name: perPage
in: query
required: false
schema:
type: integer
minimum: 10
maximum: 100
Compare the vulnerable unconstrained schema with the bounded OpenAPI definition. section 6.1
