{"success":true,"name":"enforce-request-body-size-and-depth-limits-at-the-api-edge","description":"An API accepts JSON bodies with no limit on size or nesting","category":"ai-brimind","path":"ai-brimind/enforce-request-body-size-and-depth-limits-at-the-api-edge/SKILL.md","file":"SKILL.md","content":"---\nname: enforce-request-body-size-and-depth-limits-at-the-api-edge\ndescription: \"An API accepts JSON bodies with no limit on size or nesting\"\n---\n\n# Enforce Request Body Size and Depth Limits at the API Edge\n\n## When to use\nYour endpoints parse client-sent bodies, and nothing bounds how large, deep, or repetitive those payloads can be.\n\n## Example request\n100MB JSON posted to a form endpoint → parser eats the memory and the instance falls over; a body size limit is the first wall. — Deeply nested JSON bomb → recursive parsing blows the stack; parser depth limits exist for exactly this. — Array field sent with a million entries → validation loops for minutes per request; per-field length caps belong in the schema. — Limits set only in app code → the giant body is already buffered before rejection; the web server/gateway layer should refuse it earlier.\n\n## Instructions\nAct as an edge-defense developer who assumes some client will eventually send the largest, deepest payload physically possible. For body handling: 1) Set a global max body size at the outermost layer available (web server, gateway, framework body parser) so oversized payloads are refused before your code buffers them — check the current defaults instead of assuming they're sane for your case. 2) Size per route by need: a login body needs a few KB; only upload/import routes get big limits, explicitly. 3) In validation schemas, cap the unbounded dimensions: max array lengths, max string lengths, max nesting — every 'list of things' from a client needs a ceiling. 4) Reject with the proper signals (413 for too large, 400 for structure violations) using the standard error envelope so clients learn the rule. 5) Test the limits for real: send an over-limit body and confirm rejection happens early and cheap. Only consider the edge hardened once oversized and over-nested payloads are confirmed refused before doing damage, and explain how each cap protects memory and CPU rather than inconveniencing normal clients.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #916\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}