The vulnerability lies in the absence of input validation for parameters that control the number of items returned by various REST API endpoints and other data-fetching mechanisms in XWiki. The parameters, typically named 'number' or 'limit', were passed directly to database queries or in-memory processing loops. An attacker could specify a very large or negative value for this parameter, causing the server to attempt to fetch and process an enormous number of records. This would lead to excessive CPU and memory consumption, resulting in an OutOfMemoryError or a denial of service (DoS), making the wiki unresponsive.
The patch addresses this by introducing a centralized validation method, validateAndGetLimit(Integer limit), in the base XWikiResource class. This method checks the provided limit against a configurable system-wide query item limit (security.queryItemsLimit). If the requested limit is missing, it defaults to the configured value. If it's invalid (e.g., negative or exceeds the maximum allowed), it throws a WebApplicationException with a 400 Bad Request status, immediately stopping the request. This new validation method is then applied across dozens of resource implementation classes, effectively mitigating the vulnerability in all affected REST endpoints. The patch also extends this protection to UI components driven by Velocity templates by introducing and using new validation macros (#validateQueryLimit, #getAndValidateQueryLimitFromRequest).