Archived
vendor: the pattern parser counts its nesting, and refuses past 64
A tool schema's `pattern` reaches the grammar converter as client data,
and the group scanner recursed once per nested '(': a few tens of KB of
brackets inside one JSON string was an uncatchable stack overflow of the
request worker. The body's depth and value bounds never saw it -- the
brackets are string content, not JSON nesting -- and 0003, the patch that
made this same function survive a hostile pattern, hardened the empty and
the looping cases but never the recursing one. It is the one remote crash
in the audit, and one request is the whole attack.
transform() now counts its nesting and records the refusal once, where
every unwinding frame met the same '(' and repeated it; check_errors turns
it into the clean throw the server already answers with a 400. Proven on
the compile host against the real converter: the 20000-group pattern is
refused by name, a 40-group pattern -- far past anything a real schema
nests -- still compiles. The record keeps the addition under 0003's name,
whose footing it stands on.
This commit is contained in:
1 parent
b83d53cf19
commit
2fda03ccdd
4 files changed
+46
-2
No files matched your search
+22
@@ -590,7 +590,29 @@ private:
|
||||
auto s = ls.first;
|
||||
return is_literal ? "\"" + s + "\"" : s;
|
||||
};
|
||||
int pw_nesting = 0;
|
||||
bool pw_too_deep = false;
|
||||
constexpr int kMaxPatternNesting = 64;
|
||||
std::function<literal_or_rule()> transform = [&]() -> literal_or_rule {
|
||||
// RADIANCE: `client_pattern` is client data, and every nested `(` recurses this
|
||||
// lambda once. A few tens of KB of '(' is an uncatchable stack overflow of the
|
||||
// request worker -- the JSON depth and value bounds cannot help, because the
|
||||
// brackets are string content, not JSON nesting. A pattern nesting past a depth
|
||||
// no real one reaches is refused like any other unsupported syntax. Once only:
|
||||
// every unwinding frame meets the same '(' again, and the error text travels.
|
||||
if (++pw_nesting > kMaxPatternNesting) {
|
||||
--pw_nesting;
|
||||
if (!pw_too_deep) {
|
||||
_errors.push_back("Pattern nests groups more than " +
|
||||
std::to_string(kMaxPatternNesting) + " deep");
|
||||
pw_too_deep = true;
|
||||
}
|
||||
return std::make_pair(std::string(), false);
|
||||
}
|
||||
struct Leave {
|
||||
int& d;
|
||||
~Leave() { --d; }
|
||||
} leave{ pw_nesting };
|
||||
size_t start = i;
|
||||
std::vector<literal_or_rule> seq;
|
||||
|
||||
|
||||
Reference in new issue
Block a user