Scrapy vulnerable to ReDoS via XMLFeedSpider
Scrapy's XMLFeedSpider and related functions used vulnerable regular expressions for parsing, allowing a malicious response to cause extreme CPU and memory usage. An attacker could trigger a denial of service by supplying crafted content.
scrapy/scrapy
Originally disclosed on huntr
Impact
The following parts of the Scrapy API were found to be vulnerable to a ReDoS attack:
-
The
XMLFeedSpiderclass or any subclass that uses the default node iterator:iternodes, as well as direct uses of thescrapy.utils.iterators.xmliterfunction. -
Scrapy 2.6.0 to 2.11.0: The
open_in_browserfunction for a response without a base tag.
Handling a malicious response could cause extreme CPU and memory usage during the parsing of its content, due to the use of vulnerable regular expressions for that parsing.
Patches
Upgrade to Scrapy 2.11.1.
If you are using Scrapy 1.8 or a lower version, and upgrading to Scrapy 2.11.1 is not an option, you may upgrade to Scrapy 1.8.4 instead.
Workarounds
For XMLFeedSpider, switch the node iterator to xml or html.
For open_in_browser, before using the function, either manually review the response content to discard a ReDos attack or manually define the base tag to avoid its automatic definition by open_in_browser later.
Acknowledgements
This security issue was reported by @nicecatch2000 through huntr.com.
From the GitHub Advisory Database (GHSA-cc65-xxvf-f7r9, CC BY 4.0).
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the regular expressions used for parsing XML and for handling responses without a base tag were not designed to handle adversarial input efficiently, leading to catastrophic backtracking.
Impact
An attacker could cause a denial of service by making Scrapy consume excessive CPU and memory when parsing a malicious response.
What the attacker needed
Scrapy processes a malicious response; Using XMLFeedSpider with default iterator or open_in_browser
The fix
The issue was fixed in Scrapy 2.11.1 (and 1.8.4 for older versions); workarounds include switching the node iterator or manually reviewing response content.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Some parts of Scrapy used regular expressions (patterns for matching text) that can become extremely slow when given specially crafted input. An attacker who can make Scrapy process a malicious response could cause the program to use huge amounts of CPU and memory, effectively freezing it. This is called a regular expression denial of service (ReDoS).
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.