CVE-2021-28957: Lxml Cross-Site Scripting Vulnerability

MODERATE
Advisory Identifier: GHSA-jq4v-f5q6-mjqq
CVSS 6.1
CWE-79
Published
Advisory Summary

CVE-2021-28957 is a MODERATE (CVSS 6.1) cross-site scripting vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting Lxml libraries in the PyPI ecosystem. The issue involves lxml vulnerable to cross-site scripting. Remediation is available by upgrading affected packages to version 4.6.3.

CVE-2021-28957 at a Glance

CVE Identifier CVE-2021-28957
GHSA Identifier GHSA-jq4v-f5q6-mjqq
Severity MODERATE
CVSS v3.1 Base Score 6.1
CWE Classification CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Affected Product Lxml
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 6.1

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Changed (S:C)
Confidentiality Low (C:L)
Integrity Low (I:L)
Availability None (A:N)

How to Fix CVE-2021-28957

To remediate this vulnerability, upgrade all affected Lxml dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

lxml fixed: 4.6.3
pip install lxml>=4.6.3
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show lxml

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2021-28957, inspect your installed packages using pip:

pip show lxml

Analyze the terminal output to locate any version of Lxml in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 4.6.3), your application is affected.

Note: The pip show lxml command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), where the product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. In Lxml, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

An XSS vulnerability was discovered in the python `lxml` clean module versions before 4.6.3. When disabling `the safe_attrs_only` and `forms` arguments, the `Cleaner` class does not remove the `formaction` attribute allowing for JS to bypass the sanitizer. A remote attacker could exploit this flaw to run arbitrary JS code on users who interact with incorrectly sanitized HTML. This issue is patched in `lxml` 4.6.3.

CVE-2021-28957 Affected Lxml Versions

1 component(s)
Fixed Versions:
4.6.3
Product / Package Ecosystem Affected Versions Fixed Version
lxml
PyPI
< 4.6.3
4.6.3

References

NVD — CVE-2021-28957 NVD
https://nvd.nist.gov/vuln/detail/CVE-2021-28957
Lxml Source Repository REPOSITORY
https://github.com/lxml/lxml/pull/316
Lxml Source Repository REPOSITORY
https://github.com/lxml/lxml/pull/316/commits/10ec1b4e9f93713513a3264ed6158af22492f270
Security Fix Commit FIX COMMIT
https://github.com/lxml/lxml/commit/2d01a1ba8984e0483ce6619b972832377f208a0d
Security Fix Commit FIX COMMIT
https://github.com/lxml/lxml/commit/a5f9cb52079dc57477c460dbe6ba0f775e14a999
Lxml Security Information SECURITY
https://www.oracle.com/security-alerts/cpuoct2021.html
Lxml Security Information SECURITY
https://www.debian.org/security/2021/dsa-4880
Lxml Security Information SECURITY
https://security.netapp.com/advisory/ntap-20210521-0004
Lxml Security Information SECURITY
https://security.gentoo.org/glsa/202208-06
pypi.org/project/lxml WEB
https://pypi.org/project/lxml
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/XXN3QPWCTQVOGW4BMWV3AUUZZ4NRZNSQ
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/3C2R44VDUY7FJVMAVRZ2WY7XYL4SVN45
lists.debian.org/debian-lts-announce... WEB
https://lists.debian.org/debian-lts-announce/2021/03/msg00031.html
Lxml Source Repository REPOSITORY
https://github.com/pypa/advisory-database/tree/main/vulns/lxml/PYSEC-2021-19.yaml
Lxml Source Repository REPOSITORY
https://github.com/lxml/lxml
GitHub Advisory / Wiki ADVISORY
https://github.com/advisories/GHSA-jq4v-f5q6-mjqq
bugs.launchpad.net/lxml/+bug/1888153 WEB
https://bugs.launchpad.net/lxml/+bug/1888153

Frequently Asked Questions

What is CVE-2021-28957?
CVE-2021-28957 is a security vulnerability in Lxml involving lxml vulnerable to Cross-Site Scripting under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
Which Lxml versions are affected?
Affected versions include releases prior to 4.6.3 across affected packages: lxml.
What version fixes CVE-2021-28957?
Upgrading to 4.6.3 (or the latest patched release for your respective branch) resolves the vulnerability.
Is lxml affected?
Yes, lxml is affected in releases prior to 4.6.3. Upgrade your dependency to 4.6.3 or later.
What is the CVSS score of CVE-2021-28957?
CVE-2021-28957 has a CVSS v3.1 base score of 6.1 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N.
What CWE is associated with CVE-2021-28957?
CVE-2021-28957 is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.).
How can I check PyPI dependencies for CVE-2021-28957?
Run the dependency tree command: 'pip show lxml'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-jq4v-f5q6-mjqq",
  "modified" : "2024-09-30T16:54:23Z",
  "published" : "2021-03-22T16:53:53Z",
  "aliases" : [ "CVE-2021-28957" ],
  "summary" : "lxml vulnerable to Cross-Site Scripting ",
  "details" : "An XSS vulnerability was discovered in the python `lxml` clean module versions before 4.6.3. When disabling `the safe_attrs_only` and `forms` arguments, the `Cleaner` class does not remove the `formaction` attribute allowing for JS to bypass the sanitizer. A remote attacker could exploit this flaw to run arbitrary JS code on users who interact with incorrectly sanitized HTML. This issue is patched in `lxml` 4.6.3.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "lxml"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "4.6.3"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-28957"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/lxml/lxml/pull/316"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/lxml/lxml/pull/316/commits/10ec1b4e9f93713513a3264ed6158af22492f270"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/lxml/lxml/commit/2d01a1ba8984e0483ce6619b972832377f208a0d"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/lxml/lxml/commit/a5f9cb52079dc57477c460dbe6ba0f775e14a999"
  }, {
    "type" : "WEB",
    "url" : "https://www.oracle.com/security-alerts/cpuoct2021.html"
  }, {
    "type" : "WEB",
    "url" : "https://www.debian.org/security/2021/dsa-4880"
  }, {
    "type" : "WEB",
    "url" : "https://security.netapp.com/advisory/ntap-20210521-0004"
  }, {
    "type" : "WEB",
    "url" : "https://security.gentoo.org/glsa/202208-06"
  }, {
    "type" : "WEB",
    "url" : "https://pypi.org/project/lxml"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/XXN3QPWCTQVOGW4BMWV3AUUZZ4NRZNSQ"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/3C2R44VDUY7FJVMAVRZ2WY7XYL4SVN45"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2021/03/msg00031.html"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/lxml/PYSEC-2021-19.yaml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/lxml/lxml"
  }, {
    "type" : "ADVISORY",
    "url" : "https://github.com/advisories/GHSA-jq4v-f5q6-mjqq"
  }, {
    "type" : "WEB",
    "url" : "https://bugs.launchpad.net/lxml/+bug/1888153"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-79" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-03-22T16:52:59Z",
    "nvd_published_at" : "2021-03-21T05:15:00Z"
  }
}