GHSA-CRC3-R666-FWC8
`:lang()` checks every value of its list against every element
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-CRC3-R666-FWC8 divulgada · CVSS 3.7 (GitHub) | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
`:lang()` accepts a comma-separated list of language ranges. Soup Sieve checks an element's language against every
value in the list, without stopping when one matches. It also checks the list again for every element, even when many
elements share the same language. A single `:lang()` with thousands of values therefore costs time proportional to the
number of values times the number of elements.
Soup Sieve does not limit the length of a selector string. `max_selectors` limits the number of selectors, and a
`:lang()` list is one selector however many values it has. So an application that compiles untrusted selectors and
relies on `max_selectors` to bound them does not bound this cost.
Details
For each element, `match_lang()` resolves the element's language, then calls `extended_language_filter()` for every
value of every `:lang()` list in the selector. Nothing records the result for that language, and the loop over values
does not end at the first match. So 7,500 values on 1,000 elements make 7,500,000 comparisons, even when every element
has the same language or none.
The cost is linear in the length of the selector and in the size of the document. It does not grow faster than either.
Any selector costs more as it gets longer, but a list of `:lang()` values is the cheapest way to make a selector cost
more per byte.
`max_selectors` counts the selectors in a selector list and the parts of compound and complex selectors. It does not
count the values in the argument of a pseudo-class, and it is not a limit on the length of the selector string.
Soup Sieve does not limit the length of selector strings, and does not guarantee protection against long ones. The
time to match grows with the length of the selector, whatever the selector is made of, and no option of Soup Sieve
bounds it. If long selector strings are a concern, for example because selectors come from untrusted input, limiting
their length is the responsibility of the application, before it passes them to Soup Sieve.
Proof of concept
import soupsieve as sv
from bs4 import BeautifulSoup
soup = BeautifulSoup('<div lang="en">x</div>' * 1000, 'html.parser')
sel = ':lang(' + ','.join(['x-v{}'.format(i) for i in range(7500)]) + ')' # 57.5 KB, one selector
sv.select(sel, soup)Measured on one machine, with 1,000 elements:
| Selector | Size | 4.1.1, no `lang` | 4.1.1, `lang="en"` | Fixed, either |
|---|---|---|---|---|
| `:lang()` with 3,750 values | 11.0 KB | 0.09 s | 1.6 s | 0.003 s |
| `:lang()` with 7,500 values | 22.0 KB | 0.17 s | 3.2 s | 0.005 s |
| `:lang()` with 7,500 distinct values | 57.5 KB | 0.18 s | 3.6 s | 0.005 s |
Impact
An application that compiles selectors from untrusted input can be made to spend CPU time proportional to the length
of the selector times the size of the document. This needs an attacker who controls the selector, and a document large
enough for the time to matter. It does not affect applications that only use their own selectors.
Soup Sieve's documentation already advises that taking untrusted selectors in a time-critical system needs a way to
abort long-running operations.
Affected versions
4.1.1 and earlier.
Patched versions
4.1.2
Fix
- `:lang()` stops checking an element's language against a list as soon as one value matches.
- The result of matching a language against a `:lang()` list is cached for the duration of a call such as
- The documentation now states that `max_selectors` limits the number of selectors, not their length or the values in
With the fix, the cost of a `:lang()` list is proportional to the number of values times the number of distinct
languages in the document, which is usually small.
Mitigation
For versions before the fix, and as good practice for any application that accepts untrusted selectors:
- Limit the length of selector strings before compiling them, for example by rejecting any selector longer than your
- If `:lang()` is not needed, disable it with the `ignore` option, for example `sv.compile(selector, ignore=[':lang'])`.
- Run selector matching with a time limit, or in a worker that can be stopped, when the selectors or documents come
Severity
Low, `CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L` (3.7). The cost is linear, and it needs an application that
compiles untrusted selectors and matches them against large documents.
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
pypisoupsieve |
Sin parche | — | — | 4.1.2 afectada |
Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/facelessuser/soupsieve/security/advisories/GHSA-crc3-r666-fwc8Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
