From 2aacf44c557ae430120a081af554e70baa67f0ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 22 Oct 2026 21:48:52 +0200 Subject: [PATCH] markdown: reject pathologically nested markup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Building the DOM is quadratic in nesting depth and raw HTML from a paste reaches it verbatim, so a megabyte of `
` was a quarter million levels deep and cost around 87 seconds of CPU per request — on a blocking thread the request timeout does not stop. Prose stays around a dozen levels, so cap the depth at 256 and answer with a bad request instead. The depth is measured by running html5ever's own tree builder, set up as ammonia sets it up, over a sink that keeps nothing but where each node hangs. Estimating it from the tags falls short of the parser at every turn: a close tag naming nothing that is open closes nothing, and neither does one in a comment, an attribute value or a `", + "
</div>", + "
", + // A `", + "