A public method walks caller-supplied nested structures with no depth limit. Enough nesting runs the stack out and takes the whole process with it.
What goes wrong
One JSON document, nested deep enough, is all it takes to drop the process. Converting one data format to another usually means a recursive walk: handle a node, then recurse into its children. Clean and obvious. The catch is that the depth of that recursion is set by the input, and the input comes from whoever is calling.
Feed it an object nested a few tens of thousands of levels deep and the conversion functions call each other until the thread's stack is gone. Nothing catches that. The process dies. Building the payload is a one-line loop, and the request that carries it looks like ordinary JSON.
The pattern
function toBinary(node) {
if (isMap(node)) {
for (const [k, v] of entries(node))
out.put(k, toBinary(v)) // recurses as deep as the input
} else if (isList(node)) {
for (const item of node) toBinary(item)
}
return out
}function toBinary(node, depth = 0) {
if (depth > MAX_DEPTH) throw new Error("nesting too deep")
if (isMap(node)) {
for (const [k, v] of entries(node))
out.put(k, toBinary(v, depth + 1))
} else if (isList(node)) {
for (const item of node) toBinary(item, depth + 1)
}
return out
}Every gate held. The exploit path was reproduced against a negative control, the impact was calibrated, and the finding was signed report-ready.
Why it matters to you
This one is rated moderate for a reason: it is a crash, not a breach. But a crash on demand is still an outage on demand. If the conversion sits behind an unauthenticated endpoint, anyone can restart your workers whenever they feel like it.
Depth limits are the kind of guard you add once and forget. Pick a maximum nesting depth comfortably above anything real traffic produces, and reject the rest.
Check your own code
- Find every recursive parse, convert, or serialize routine that runs on untrusted input.
- Add an explicit depth counter and a hard ceiling to each one.
- Prefer an iterative walk with your own stack where the format allows it.
- Add a test that sends deeply nested input and asserts a clean rejection, not a crash.