Cluster 9 · OWASP API4:2023 · maxItems · maxLength · limit

Preventing API4 Resource Exhaustion (maxItems, maxLength, maximum, Pagination)

Stop memory exhaustion, regex backtracking, and database table dumps (OWASP API4:2023) by adding explicit maxLength, maxItems, maximum, and bounded page-size contracts across OpenAPI schemas.

Zero Telemetry · Strict CSP (connect-src 'none')

1. Paste OpenAPI Spec (Quick-Lint) & Controls

OAS 2.0 / 3.0 / 3.1 · OWASP API Top 10
Parsed JSON OpenAPI 3.0.1 · 2 ops · 1 {id} routes · 1 nullable: true · ~522 tok
OWASP API Top 10 & MCP Readiness Checklist (100 Points)
Moderate Schema / Auth Gaps
75 / 100 (C)
CONDITIONAL — FIX GAPS IN PR

Passing: 6 · Fixes Needed: 2 · Target: OpenAPI 3.1.0

Est. MCP Schema Tokens
2,172 tok
$9.77/mo at 50 turns/day ($3/1M)
Reclaimable Diet Savings
-792 tok
Saves $3.56/mo via MCPDiet
API2-AUTH (OWASP API2:2023): Explicit components.securitySchemes (Bearer JWT / OAuth2 scopes) + global/op security PASS
Bearer JWT / OAuth2 securitySchemes and security[] requirements are enforced.
API1-BOLA (OWASP API1:2023): Object-ID routes ({id}) enforce explicit 401/403 responses & tenant ownership scopes PASS
Parameterized {id} endpoints verify tenant ownership and document 401/403 status codes.
API3-BOPLA (OWASP API3:2023): additionalProperties: false + readOnly: true on server-owned fields (role, id, plan) PASS
Request schemas lock additionalProperties: false and protect server fields with readOnly: true.
API4-BOUNDS (OWASP API4:2023): maxLength, maxItems, maximum & bounded pagination (limit <= 100 / cursor) on inputs CRITICAL FIX
Unbounded arrays/strings and uncapped ?limit= queries expose memory/CPU DoS vectors (OWASP API4).
API8-TLS (OWASP API8:2023): HTTPS-only servers[] URLs (zero http:// prod) + strict CORS allowlist & headers PASS
Production servers[] enforce HTTPS-only URLs and strict origin allowlist CORS.
API4-429 (OWASP API4 / API8): Explicit 401, 403 & 429 Too Many Requests responses with Retry-After / X-RateLimit-* HIGH FIX
Missing 429 rate-limit contracts and Retry-After headers leave brute-force and scraping throttles undocumented.
API9-INV (OWASP API9:2023): Versioned base paths + deprecated: true ops declare Sunset header & replacement path PASS
Deprecated endpoints publish Sunset headers and migration paths; zero shadow APIs.
MCP-TOKEN (AI / MCP Readiness): Concise tool descriptions (<= 120 tok/op) & OpenAPI 3.1 type arrays (no nullable: true) PASS
Operation descriptions stay lean (~51 tok/op) and OpenAPI 3.1.0 avoids nullable drift.
openapi-owasp-remediation.yaml
openapi: "3.1.0"
info:
  title: "Batch & Search Query API"
  version: "1.0.0"
components:
  schemas:
    WorkspaceMemberCreateRequest:
      type: object
      additionalProperties: false
      required:
        - email
      properties:
        id:
          type: string
          format: uuid
          readOnly: true
        role:
          type: string
          readOnly: true
        email:
          type: string
          format: email
          maxLength: 254
        tags:
          type: array
          maxItems: 20
          items:
            type: string
            maxLength: 32
        nickname:
          type:
            - string
            - "null"
          maxLength: 64
  responses:
    Unauthorized401:
      description: Missing or invalid Bearer JWT / OAuth2 token
    Forbidden403:
      description: Authenticated caller lacks tenant/object ownership scope
    TooManyRequests429:
      description: Rate limit exceeded
      headers:
        Retry-After:
          schema:
            type: integer
            minimum: 1
            maximum: 3600
        X-RateLimit-Remaining:
          schema:
            type: integer
            minimum: 0
paths:
  /v1/workspaces/{workspaceId}/members:
    get:
      operationId: listWorkspaceMembers
      description: List members for a tenant workspace.
      parameters:
        - name: workspaceId
          in: path
          required: true
          schema:
            type: string
            format: uuid
            maxLength: 36
        - name: limit
          in: query
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 25
      responses:
        "200":
          description: Bounded member page
        "401":
          $ref: "#/components/responses/Unauthorized401"
        "403":
          $ref: "#/components/responses/Forbidden403"
        "429":
          $ref: "#/components/responses/TooManyRequests429"
Zero-Upload SpecDiff $49 Remediation PR

Audit Full OpenAPI Specs or Ship a Hardened PR Today

Run a 100% browser-side breaking-change diff, OWASP API Top 10 scan & SARIF 2.1.0 export on SpecDiff (https://spec.runglab.dev), order a $49 Done-For-You OpenAPI & MCP Remediation PR on Creem, or automate via POST /v1/openapi/audit (API Hub), remote MCP tool audit_openapi_spec, and Apify Cloud PPE.

OpenAPI Controls, Bounds & Verification Reference

Rule / Control Hardened Pattern Security & Token Rationale
String Length Ceiling minLength + maxLength (e.g. <= 254 / 2000) Blocks 10MB string payloads and ReDoS attacks on regex patterns
Array Cardinality Cap maxItems: 50 (or <= 100) Prevents N+1 batch fan-out and OOM spikes on bulk endpoints
Numeric / Page Limit minimum: 1, maximum: 100 Stops `?limit=99999999` full-table scans on list endpoints
File / Payload Cap 413 Payload Too Large + timeouts Documents gateway body limits cleanly for client SDK retries

OWASP API4 Bounded Strings, Arrays & Cursor Pagination Schema

api4-bounded-schemas.yaml
components:
  parameters:
    PageLimit:
      name: limit
      in: query
      schema:
        type: integer
        minimum: 1
        maximum: 100
        default: 25
    PageCursor:
      name: cursor
      in: query
      schema:
        type: string
        maxLength: 256
  schemas:
    BatchTagRequest:
      type: object
      additionalProperties: false
      required: [ids, tags]
      properties:
        ids:
          type: array
          minItems: 1
          maxItems: 50
          items:
            type: string
            format: uuid
            maxLength: 36
        tags:
          type: array
          maxItems: 20
          items:
            type: string
            minLength: 1
            maxLength: 32
        comment:
          type: string
          maxLength: 1000

Detect Unbounded Schemas with jq in Seconds

check-api4-bounds.sh
# Find string/array schemas missing maxLength or maxItems in openapi.json:
jq '[.. | objects | select(.type == "string" and (.maxLength == null) and (.enum == null) and (.format != "uuid"))] | length' openapi.json
jq '[.. | objects | select(.type == "array" and (.maxItems == null))] | length' openapi.json

# Or audit + patch all API4 rules automatically on https://spec.runglab.dev

Key Engineering Takeaways

  • Every unbounded `type: string` or `type: array` in an OpenAPI schema is an open invitation for multi-megabyte JSON bombs, ReDoS stalls, or batch-loop database exhaustion.
  • API gateways (Cloudflare, Envoy, Kong, AWS API Gateway) and OpenAPI request validators can enforce `maxLength`, `maxItems`, and `maximum` at the edge before your app server parses a byte.
  • In AI/MCP workflows, bounded `maxItems` and `maximum` also prevent hallucinated LLM tool arguments (`limit: 100000`) from crashing backend pagination.

Common Contract Pitfalls to Avoid

  • Setting `type: integer` on `page` / `limit` query parameters without `minimum: 1` and `maximum: 100`.
  • Applying complex nested `pattern:` regexes to strings that have no `maxLength` cap.
  • Returning unbounded nested arrays in `200 OK` list endpoints without cursor pagination.

More OpenAPI OWASP & MCP Optimization Guides

← Back to OpenAPI OWASP & MCP Scorer Hub · 2026 N=26 OpenAPI & MCP Benchmark → · MCP Context Token Cost Calculator → · CORS Preflight & Webhook HMAC Debugger → · SpecDiff Live Diff & SARIF → · $49 Remediation PR →

Frequently Asked Questions

What maxItems and maximum values should standard SaaS APIs use?

Most B2B APIs cap `limit` at `maximum: 100` (default `25`), array batch inputs at `maxItems: 20..100`, short identifiers/emails at `maxLength: 36..254`, and freeform notes at `maxLength: 1000..4000`.

Does adding maxLength / maxItems break existing clients?

Adding bounds to an already-live endpoint is a potential breaking change if legitimate callers exceed the cap — use SpecDiff (https://spec.runglab.dev) to check SemVer impact before tightening limits.

How does API4 relate to HTTP 429 rate-limit responses?

OWASP API4 covers both payload/compute bounds (maxLength, maxItems, pagination) and request-rate throttling (429 Too Many Requests with Retry-After headers).