Repository navigation
fix(server): reject requests with excessive JSON nesting depth - #27434
doringeman wants to merge 1 commit into
Conversation
Signed-off-by: Dorin Geman <dorin.geman@docker.com>
|
cc @ngxson SECURITY.md puts DoS out of scope, so I read this as a plain robustness fix rather than a security one: a malformed request should never take the process down, and the bound is local with no runtime cost. Do you agree we take it on that basis, and how do you want this kind of report framed in general, since the description and the test here are worded as a security finding? Second question, on the constant: 64 leaves around 19 levels of real nesting once the OAI envelope and the properties layers of a JSON schema are counted, which machine generated tool schemas can plausibly exceed. Any reason not to go higher, say 256, still far below where the stack actually gives out? |
|
I was able to reproduce the fix locally. Agreed that it's a robustness fix, but I think this is more likely a bug in Will see if there is a better fix. |
|
That’s the right question! Technically, it’s up to the library not to crash. But they likely think the same way: you don’t arbitrarily limit local resources. |
|
Opus 5 say : nlohmann already exposes the depth: parser_callback_t is bool(int depth, parse_event_t, basic_json &) and the depth passed is the parser stack size, so we can reject at object_start/array_start without writing a scanner of our own. The catch is that passing a callback switches the parser to the callback DOM path, which does extra work per token, so on multi MB payloads it may well cost more than the single byte pass. Worth measuring before picking one. On the upstream side, they already made the destructor iterative and the parser is iterative too, so what is left recursive is the copy constructor and dump(), which is where this actually dies. A depth cap at parse time does not help when the json comes from somewhere else, so the real library fix is making those two iterative, with the destructor as precedent. |
|
I mean, the first step should be to search if anyone already trying to fix upstream nlohmann/json — issues
nlohmann/json — PRs
|
|
since many fixes are already discussed / merged upstream, I'd suggest joining one of the discussion above OSS maintainers in general don't want duplicated efforts, let's try to keep it low noise for both llama.cpp and upstream nlohmann::json |
|
Thank you @ServeurpersoCom @ngxson. |
|
Nice, that was the right move: nlohmann/json#1788 asked for the same thing back in 2019 and the bot closed it in 2020 without anyone acting on it, so a fresh report with a working repro is exactly what was missing. |
|
Closing this to avoid duplicated work, since the fix belongs upstream and nlohmann/json#5389 is now open on exactly this. |
Overview
Flagging and fixing a denial of service, where a deeply nested array terminates the process, including any same-model work in-flight.
Additional information
Before:
Now:
Requirements
The root cause wasn't identified by AI. I wrote the PR description myself.