GHSA-r925-mgvr-h9cc: Composer/symfony/symfony vulnerability
Description
HeaderUtils::split() parsed header values with a pattern whose token alternative also matched whitespace, followed by a (?<!\s) lookbehind. A run of whitespace placed before a separator could be divided among the iterations of the enclosing repetition in exponentially many ways, and the engine tried all of them before settling. HeaderBag calls it for the Cache-Control header whenever a Request is built, so any application handling HTTP requests is reachable, with no authentication.
A single request carrying such a header costs close to a second of CPU (813 ms for a run of 17 spaces in an 8 KB header on PHP 8.5, doubling with each extra space). From 18 spaces on, pregmatchall() gives up at pcre.backtracklimit and split() returns an empty array, so every directive of the header is silently dropped.
Resolution
The pattern now consumes whitespace only when more of the value follows it, so a value can no longer end on whitespace, nothing has to be given back, and every quantifier is possessive. The first release of this fix broke splitting on a whitespace separator: HeaderUtils::split('foo bar', ' ') returned a single value in 6.4.46 to 6.4.47, 7.4.19 to 7.4.20 and 8.1.7 to 8.1.8. Whitespace characters used as separators are now left out of the whitespace branch, which 6.4.48, 7.4.21 and 8.1.9 contain.
The patches for this issue are available here for branch 5.4 (and forward-ported to 6.4, 7.4, 8.1 and 8.2).
Credits
Symfony would like to thank r3verii for reporting the issue and Nicolas Grekas for providing the fix.
Symfony would also like to thank Bruno Dias from Checkmarx for his help getting a CVE assigned.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
composer/symfony/symfonyto a version that resolves this vulnerability.Fixed in 5.4.54 - Upgrade
Upgrade
composer/symfony/http-foundationto a version that resolves this vulnerability.Fixed in 5.4.54 - Upgrade
Upgrade
composer/symfony/symfonyto a version that resolves this vulnerability.Fixed in 8.1.7 - Upgrade
Upgrade
composer/symfony/symfonyto a version that resolves this vulnerability.Fixed in 7.4.19 - Upgrade
Upgrade
composer/symfony/symfonyto a version that resolves this vulnerability.Fixed in 6.4.46 - Upgrade
Upgrade
composer/symfony/http-foundationto a version that resolves this vulnerability.Fixed in 8.1.7 - Upgrade
Upgrade
composer/symfony/http-foundationto a version that resolves this vulnerability.Fixed in 7.4.19 - Upgrade
Upgrade
composer/symfony/http-foundationto a version that resolves this vulnerability.Fixed in 6.4.46 - Upgrade
Upgrade
symfony/symfonyto a version that resolves this vulnerability.Patch 343a1772ce6ac03e48b228d2d7168d19750e3f36
Event History
Frequently Asked Questions
Which deployments are exposed to this issue?
Any application that handles HTTP requests and builds a Request object is reachable because HeaderBag processes the Cache-Control header. No authentication is required.
What must an attacker send to trigger the expensive processing?
An attacker needs to send a request with a Cache-Control header containing a run of whitespace before a separator. A single such request can consume close to a second of CPU in the described benchmark, with processing time doubling for each additional space.
Can exploitation affect header interpretation as well as CPU usage?
Yes. From 18 spaces onward in the described case, preg_match_all() reaches pcre.backtrack_limit and split() returns an empty array, causing every Cache-Control directive in that header to be silently dropped.