{"success":true,"name":"bound-the-work-one-request-can-cause-size-depth-and-time-lim","description":"Endpoint processes user content with parsing, regex, images, or math","category":"ai-brimind","path":"ai-brimind/bound-the-work-one-request-can-cause-size-depth-and-time-lim/SKILL.md","file":"SKILL.md","content":"---\nname: bound-the-work-one-request-can-cause-size-depth-and-time-lim\ndescription: \"Endpoint processes user content with parsing, regex, images, or math\"\n---\n\n# Bound the Work One Request Can Cause: Size, Depth, and Time Limits\n\n## When to use\nYou are writing code where user-supplied content drives processing — regex matching, JSON parsing, image resizing, archive extraction, big loops — with no explicit limits.\n\n## Example request\nA clever regex validates user text → certain crafted strings make some regex patterns take minutes of CPU, freezing the server with one request (ReDoS / catastrophic backtracking). Accepting any JSON body → a deeply nested or 100 MB payload eats memory before your logic even runs; body size and depth need caps at the entry (payload limits). Extracting user-uploaded archives → a tiny zip can expand to gigabytes and fill the disk; extraction needs size and file-count ceilings (zip bomb). Generating thumbnails from any image → a malformed or enormous image pins the CPU; validate dimensions and use timeouts on processing (resource-bounded processing).\n\n## Instructions\nAct like an engineer who prices every endpoint in CPU, memory, and time, and refuses to let a stranger run up the bill with one crafted request — denial of service is not always a flood; sometimes it is a single evil input. For each place user content drives computation, set explicit ceilings before the work starts: maximum request body size enforced by the framework or server config, maximum lengths on strings that feed regexes or parsers, depth and element-count limits on nested structures, dimension and pixel checks on images before decoding, and total-size plus file-count limits when expanding archives. Treat regexes on user input as suspects: keep them simple, avoid nested quantifiers that cause catastrophic backtracking, or use a matching approach without that failure mode. Wrap genuinely heavy operations in timeouts, and move expensive work (media processing, big imports) into background jobs with their own limits so the web process stays responsive. Check what limits the framework, server, and platform already offer and switch them on before writing custom guards. Test with hostile inputs — an oversized body, a deeply nested JSON, a pathological string, a decompression bomb — and confirm the request is rejected fast instead of hanging. Only ship once the most expensive path has a stated cost ceiling, and explain how the limits keep one malicious request from becoming an outage for everyone else.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #583\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}