External API calls inside loops are batched or rate-paced
Why it matters
Sequential await calls inside a loop over user-supplied data are simultaneously a latency bomb and a cost bomb: 100 items × 200ms each = 20 seconds of wall time, and each iteration holds an HTTP connection open. When the input array is user-controlled with no length cap — for example req.body.urls.forEach(url => fetch(url)) — the number of outbound requests is directly attacker-controlled. CWE-770 applies: an unbounded array fed into a loop of external calls gives an attacker leverage over your third-party API rate limits, egress costs, and server-side connection count. Even internal N+1 patterns inflate database query counts and slow down all concurrent users.
Severity rationale
High because user-controlled array length maps directly to unbounded external API calls, enabling cost abuse and self-inflicted rate-limit bans with no cap.
Remediation
Replace sequential await-in-loop patterns with bounded concurrency using p-map. Combine with a schema-level array length cap to prevent the input from growing arbitrarily.
import { z } from 'zod'
import pMap from 'p-map'
const ScrapeSchema = z.object({
urls: z.array(z.string().url()).max(50),
})
export async function POST(req: Request) {
const { urls } = ScrapeSchema.parse(await req.json())
const results = await pMap(
urls,
async (url) => {
const res = await fetch(url, { signal: AbortSignal.timeout(5000) })
return res.text()
},
{ concurrency: 5 },
)
return Response.json({ results })
}
The concurrency cap of 5 prevents saturating your outbound connection pool regardless of input size.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Hidden Cost Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-770 — Allocation of Resources Without Limits or Throttling
- iso-25010:2011 · performance-efficiency
Taxons
History
- 2026-04-18·v1.0.0·Initial import from ai-slop-cost-bombs·automated