CVE-2021-29434: Wagtail Cross-Site Scripting Vulnerability

HIGH
Advisory Identifier: GHSA-wq5h-f9p5-q7fx
CVSS 6.1
CWE-79
Published
Advisory Summary

CVE-2021-29434 is a HIGH (CVSS 6.1) cross-site scripting vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting Wagtail libraries in the PyPI ecosystem. The issue involves improper validation of urls ('cross-site scripting') in wagtail rich text fields. Remediation is available by upgrading affected packages to version 2.11.7, 2.12.4.

CVE-2021-29434 at a Glance

CVE Identifier CVE-2021-29434
GHSA Identifier GHSA-wq5h-f9p5-q7fx
Severity HIGH
CVSS v3.1 Base Score 6.1
CWE Classification CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Affected Product Wagtail
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:H/UI:R/S:U/C:H/I:H/A:N).

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

How to Fix CVE-2021-29434

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

wagtail fixed: 2.11.7
pip install wagtail>=2.11.7
wagtail fixed: 2.12.4
pip install wagtail>=2.12.4
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 wagtail

How to Check if You Are Affected

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

pip show wagtail

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

Note: The pip show wagtail 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 Wagtail, 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

### Impact When saving the contents of a rich text field in the admin interface, Wagtail does not apply server-side checks to ensure that link URLs use a valid protocol. A malicious user with access to the admin interface could thus craft a POST request to publish content with `javascript:` URLs containing arbitrary code. The vulnerability is not exploitable by an ordinary site visitor without access to the Wagtail admin. ### Patches Patched versions have been released as Wagtail 2.11.7 (for the LTS 2.11 branch) and Wagtail 2.12.4 (for the current 2.12 branch). ### Workarounds For sites that cannot easily upgrade to a current supported version, the vulnerability can be patched by adding the following code to a `wagtail_hooks.py` module in any installed app: ```python from draftjs_exporter.dom import DOM from wagtail.admin.rich_text.converters.html_to_contentstate import ExternalLinkElementHandler, PageLinkElementHandler from wagtail.core import hooks from wagtail.core.whitelist import check_url def link_entity(props): id_ = props.get('id') link_props = {} if id_ is not None: link_props['linktype'] = 'page' link_props['id'] = id_ else: link_props['href'] = check_url(props.get('url')) return DOM.create_element('a', link_props, props['children']) @hooks.register('register_rich_text_features', order=1) def register_link(features): features.register_converter_rule('contentstate', 'link', { 'from_database_format': { 'a[href]': ExternalLinkElementHandler('LINK'), 'a[linktype="page"]': PageLinkElementHandler('LINK'), }, 'to_database_format': { 'entity_decorators': {'LINK': link_entity} } }) ``` ### Acknowledgements Many thanks to Kevin Breen for reporting this issue. ### For more information If you have any questions or comments about this advisory: * Visit Wagtail's [support channels](https://docs.wagtail.io/en/stable/support.html) * Email us at security@wagtail.io (if you wish to send encrypted email, the public key ID is `0x6ba1e1a86e0f8ce8`)

CVE-2021-29434 Affected Wagtail Versions

2 component(s)
Fixed Versions:
2.11.72.12.4
Product / Package Ecosystem Affected Versions Fixed Version
wagtail
PyPI
< 2.11.7
2.11.7
wagtail
PyPI
≥ 2.12
< 2.12.4
2.12.4

References

Frequently Asked Questions

What is CVE-2021-29434?
CVE-2021-29434 is a security vulnerability in Wagtail involving Improper validation of URLs ('Cross-site Scripting') in Wagtail rich text fields under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
Which Wagtail versions are affected?
Affected versions include releases prior to 2.11.7, 2.12.4 across affected packages: wagtail.
What version fixes CVE-2021-29434?
Upgrading to 2.11.7, 2.12.4 (or the latest patched release for your respective branch) resolves the vulnerability.
Is wagtail affected?
Yes, wagtail is affected in releases prior to 2.11.7, 2.12.4. Upgrade your dependency to 2.11.7, 2.12.4 or later.
What is the CVSS score of CVE-2021-29434?
CVE-2021-29434 has a CVSS v3.1 base score of 6.1 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:H/UI:R/S:U/C:H/I:H/A:N.
What CWE is associated with CVE-2021-29434?
CVE-2021-29434 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-29434?
Run the dependency tree command: 'pip show wagtail'. 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-wq5h-f9p5-q7fx",
  "modified" : "2024-11-19T16:02:32Z",
  "published" : "2021-04-20T14:02:30Z",
  "aliases" : [ "CVE-2021-29434" ],
  "summary" : "Improper validation of URLs ('Cross-site Scripting') in Wagtail rich text fields",
  "details" : "### Impact\nWhen saving the contents of a rich text field in the admin interface, Wagtail does not apply server-side checks to ensure that link URLs use a valid protocol. A malicious user with access to the admin interface could thus craft a POST request to publish content with `javascript:` URLs containing arbitrary code. The vulnerability is not exploitable by an ordinary site visitor without access to the Wagtail admin.\n\n### Patches\nPatched versions have been released as Wagtail 2.11.7 (for the LTS 2.11 branch) and Wagtail 2.12.4 (for the current 2.12 branch).\n\n### Workarounds\nFor sites that cannot easily upgrade to a current supported version, the vulnerability can be patched by adding the following code to a `wagtail_hooks.py` module in any installed app:\n\n```python\nfrom draftjs_exporter.dom import DOM\nfrom wagtail.admin.rich_text.converters.html_to_contentstate import ExternalLinkElementHandler, PageLinkElementHandler\nfrom wagtail.core import hooks\nfrom wagtail.core.whitelist import check_url\n\n\ndef link_entity(props):\n    id_ = props.get('id')\n    link_props = {}\n\n    if id_ is not None:\n        link_props['linktype'] = 'page'\n        link_props['id'] = id_\n    else:\n        link_props['href'] = check_url(props.get('url'))\n\n    return DOM.create_element('a', link_props, props['children'])\n\n\n@hooks.register('register_rich_text_features', order=1)\ndef register_link(features):\n    features.register_converter_rule('contentstate', 'link', {\n        'from_database_format': {\n            'a[href]': ExternalLinkElementHandler('LINK'),\n            'a[linktype=\"page\"]': PageLinkElementHandler('LINK'),\n        },\n        'to_database_format': {\n            'entity_decorators': {'LINK': link_entity}\n        }\n    })\n```\n\n### Acknowledgements\nMany thanks to Kevin Breen for reporting this issue.\n\n### For more information\nIf you have any questions or comments about this advisory:\n\n* Visit Wagtail's [support channels](https://docs.wagtail.io/en/stable/support.html)\n* Email us at security@wagtail.io (if you wish to send encrypted email, the public key ID is `0x6ba1e1a86e0f8ce8`)",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:H/UI:R/S:U/C:H/I:H/A:N"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:H/UI:P/VC:H/VI:H/VA:N/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "wagtail"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.11.7"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 2.11.6"
    }
  }, {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "wagtail"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.12"
      }, {
        "fixed" : "2.12.4"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 2.12.3"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/wagtail/wagtail/security/advisories/GHSA-wq5h-f9p5-q7fx"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-29434"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/wagtail/wagtail/commit/5c7a60977cba478f6a35390ba98cffc2bd41c8a4"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/wagtail/wagtail/commit/915f6ed2bd7d53154103cc4424a0f18695cdad6c"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/wagtail/PYSEC-2021-114.yaml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/wagtail/wagtail"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/wagtail/wagtail/compare/v2.11.6...v2.11.7"
  }, {
    "type" : "WEB",
    "url" : "https://pypi.org/project/wagtail"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-79" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-04-19T18:46:26Z",
    "nvd_published_at" : "2021-04-19T19:15:00Z"
  }
}