CVE-2024-52595
JSON

7.7high

HTML Cleaner allows crafted scripts in special contexts like svg or math to pass through

Severity
7.7high CVSS:3.1 by GitHub_M
Exploit likelihood
0.51% (higher than 44% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
GitHub_M
Also known as
GHSA-5jfw-gq64-q45fPYSEC-2024-160

Description

lxml_html_clean is a project for HTML cleaning functionalities copied from `lxml.html.clean`. Prior to version 0.4.0, the HTML Parser in lxml does not properly handle context-switching for special HTML tags such as `<svg>`, `<math>` and `<noscript>`. This behavior deviates from how web browsers parse and interpret such tags. Specifically, content in CSS comments is ignored by lxml_html_clean but may be interpreted differently by web browsers, enabling malicious scripts to bypass the cleaning process. This vulnerability could lead to Cross-Site Scripting (XSS) attacks, compromising the security of users relying on lxml_html_clean in default configuration for sanitizing untrusted HTML content. Users employing the HTML cleaner in a security-sensitive context should upgrade to lxml 0.4.0, which addresses this issue. As a temporary mitigation, users can configure lxml_html_clean with the following settings to prevent the exploitation of this vulnerability. Via `remove_tags`, one may specify tags to remove - their content is moved to their parents' tags. Via `kill_tags`, one may specify tags to be removed completely. Via `allow_tags`, one may restrict the set of permissible tags, excluding context-switching tags like `<svg>`, `<math>` and `<noscript>`.

Affected

Product or packageVersionsReported by
fedora-python lxml_html_clean< 0.4.0CVE List
lxml-html-clean (PyPI)before 0.4.0, before c5d816f86eb3707d72a8ecf5f3823e0daa1b3808GitHub Advisory Database, PyPA Advisory Database
fedoralovespython lxml_html_cleanbefore 0.4.0NVD

All scores

GitHub_M7.7high CVSS:3.1CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:L/A:H
GitHub7.7high CVSS:3.1CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:L/A:H
NVD6.1medium CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N
PyPA Advisory Database6.1medium CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N

Classification

CWE-79CWE-83CWE-184

SSVC (CISA-ADP): exploitation none, automatable no, technical impact partial.

What each source says

CVE List

lxml_html_clean is a project for HTML cleaning functionalities copied from `lxml.html.clean`. Prior to version 0.4.0, the HTML Parser in lxml does not properly handle context-switching for special HTML tags such as `<svg>`, `<math>` and `<noscript>`. This behavior deviates from how web browsers parse and interpret such tags. Specifically, content in CSS comments is ignored by lxml_html_clean but may be interpreted differently by web browsers, enabling malicious scripts to bypass the cleaning process. This vulnerability could lead to Cross-Site Scripting (XSS) attacks, compromising the security of users relying on lxml_html_clean in default configuration for sanitizing untrusted HTML content. Users employing the HTML cleaner in a security-sensitive context should upgrade to lxml 0.4.0, which addresses this issue. As a temporary mitigation, users can configure lxml_html_clean with the following settings to prevent the exploitation of this vulnerability. Via `remove_tags`, one may specify tags to remove - their content is moved to their parents' tags. Via `kill_tags`, one may specify tags to be removed completely. Via `allow_tags`, one may restrict the set of permissible tags, excluding context-switching tags like `<svg>`, `<math>` and `<noscript>`.

GitHub Advisory Database
Impact

The HTML Parser in lxml does not properly handle context-switching for special HTML tags such as <svg>, <math> and <noscript>. This behavior deviates from how web browsers parse and interpret such tags. Specifically, content in CSS comments is ignored by lxml_html_clean but may be interpreted differently by web browsers, enabling malicious scripts to bypass the cleaning process. This vulnerability could lead to Cross-Site Scripting (XSS) attacks, compromising the security of users relying on lxml_html_clean in default configuration for sanitizing untrusted HTML content.

Patches

Users employing the HTML cleaner in a security-sensitive context should upgrade to lxml 0.4.0, which addresses this issue.

Workarounds

As a temporary mitigation, users can configure lxml_html_clean with the following settings to prevent the exploitation of this vulnerability:

  • remove_tags: Specify tags to remove - their content is moved to their parents' tags.
  • kill_tags: Specify tags to be removed completely.
  • allow_tags: Restrict the set of permissible tags, excluding context-switching tags like <svg>, <math> and <noscript>.
References
NVD (es)

lxml_html_clean es un proyecto para funciones de limpieza de HTML copiadas de `lxml.html.clean`. Antes de la versión 0.4.0, el analizador HTML en lxml no manejaba correctamente el cambio de contexto para etiquetas HTML especiales como ``, `` y ``. Este comportamiento se desvía de la forma en que los navegadores web analizan e interpretan dichas etiquetas. Específicamente, lxml_html_clean ignora el contenido en los comentarios CSS pero puede ser interpretado de manera diferente por los navegadores web, lo que permite que los scripts maliciosos pasen por alto el proceso de limpieza. Esta vulnerabilidad podría conducir a ataques de Cross-Site Scripting (XSS), lo que compromete la seguridad de los usuarios que confían en lxml_html_clean en la configuración predeterminada para desinfectar contenido HTML no confiable. Los usuarios que emplean el limpiador HTML en un contexto sensible a la seguridad deben actualizar a lxml 0.4.0, que soluciona este problema. Como mitigación temporal, los usuarios pueden configurar lxml_html_clean con los siguientes ajustes para evitar la explotación de esta vulnerabilidad. Mediante `remove_tags`, se pueden especificar las etiquetas que se eliminarán; su contenido se moverá a las etiquetas de sus padres. Mediante `kill_tags`, se pueden especificar las etiquetas que se eliminarán por completo. Mediante `allow_tags`, se puede restringir el conjunto de etiquetas permitidas, excluyendo las etiquetas que cambian de contexto como ``, `` y ``.

References

Sources

SourceRecordLicence
CVE ListCVE-2024-52595 changed 2024-11-20CVE Terms of Use
GitHub Advisory DatabaseGHSA-5jfw-gq64-q45f changed 2025-01-14CC-BY-4.0
NVDCVE-2024-52595 changed 2026-06-17Public domain
PyPA Advisory DatabasePYSEC-2024-160 changed 2025-01-14CC-BY-4.0