GHSA-3F94-V2F2-4X3G
`ignore` does not disallow a pseudo-class whose name is written with a CSS escape
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:L/A:N
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-3F94-V2F2-4X3G divulgada · CVSS 3.7 (GitHub) | |
| Remediación | Parche 4.1.2 | soupsieve · 0 d desde divulgación | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
The `ignore` option makes compiling a selector fail if it uses one of the given pseudo-classes. It compared the name of
a pseudo-class as it is written in the selector, but the parser resolves CSS escapes in the name before it decides
which pseudo-class it is. So writing the name with an escape, such as `:h\61 s()` for `:has()`, used a pseudo-class
that `ignore` was meant to disallow.
An application that compiles selectors from untrusted input, and relies on `ignore` to keep out pseudo-classes it does
not want, such as ones with potential performance concerns, does not keep them out.
Details
`CSSParser.parse_selectors()` checks each pseudo-class against `ignore` with the name exactly as it is written, only
lowercased. The pseudo-class itself is found with the name after `css_unescape()`. A CSS escape is a backslash followed
by the hexadecimal code point of a character and an optional space, or by the character itself, so any letter of a name
can be escaped:
| Ignored | Selector | Before the fix |
|---|---|---|
| `:has` | `:h\61 s(> p)` | Compiles and matches as `:has(> p)` |
| `:has` | `:\68 as(> p)` | Compiles and matches as `:has(> p)` |
| `:lang` | `:l\61 ng(en)` | Compiles and matches as `:lang(en)` |
| `:nth-child` | `p:n\74 h-child(2)` | Compiles and matches as `p:nth-child(2)` |
| `:-soup-contains` | `:-soup-\63 ontains(text)` | Compiles and matches as `:-soup-contains(text)` |
This also works inside other pseudo-classes, such as `:is()` and `:not()`. Writing a name in another case, such as
`:HAS()`, did not get past `ignore`, as both names were lowercased.
Proof of concept
import soupsieve as sv
from bs4 import BeautifulSoup
soup = BeautifulSoup('<div><p>x</p></div>', 'html.parser')
try:
sv.select(':has(> p)', soup, ignore=[':has'])
except sv.SelectorSyntaxError:
print('disallowed') # printed
print(sv.select(':h\\61 s(> p)', soup, ignore=[':has'])) # [<div><p>x</p></div>] before the fixImpact
An attacker who controls a selector can use any pseudo-class that the application disallowed with `ignore`. What that
gives the attacker depends on why the application disallowed it, most often to avoid the cost of pseudo-classes that
can take long to match on large documents. Applications that do not use `ignore`, or that only compile their own
selectors, are not affected.
Affected versions
4.1.1 and earlier.
Patched versions
4.1.2
Fix
- Names are compared as the parser recognizes pseudo-classes: with CSS escapes resolved and ASCII letters in
- The documentation now states that a name is disallowed however it is written, and that a pseudo-class with an alias
Mitigation
For versions before the fix:
- Reject any selector that contains a backslash (`\`) before compiling it, if your application does not need CSS
- List every name of a pseudo-class that has an alias, such as both `:-soup-contains` and `:contains`.
- Run selector matching with a time limit, or in a worker that can be stopped, when the selectors come from untrusted
Severity
Low, `CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:L/A:N` (3.7). It needs an application that compiles untrusted selectors
and relies on `ignore` to restrict them, and it gives no more than the pseudo-classes the application meant to
disallow.
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 |
Corregida | 4.1.2 | 0 d | 4.1.2 no afectada |
4.1.2Arsenal 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-3f94-v2f2-4x3gLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
