ghsa-5286-f2rf-35c2
Vulnerability from github
7.5 (High) - CVSS:4.0/AV:N/AC:L/AT:P/PR:L/UI:P/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N
Impact
A stored cross-site scripting (XSS) vulnerability exists on ModelAdmin views within the Wagtail admin interface. A user with a limited-permission editor account for the Wagtail admin could potentially craft pages and documents that, when viewed by a user with higher privileges, could perform actions with that user's credentials. The vulnerability is not exploitable by an ordinary site visitor without access to the Wagtail admin, and only affects sites with ModelAdmin enabled.
- For page, the vulnerability is in the "Choose a parent page" ModelAdmin view (
ChooseParentView
), available when managing pages via ModelAdmin. - For documents, the vulnerability is in the ModelAdmin Inspect view (
InspectView
) when displaying document fields.
Patches
Patched versions have been released as Wagtail 4.1.4 (for the LTS 4.1 branch) and Wagtail 4.2.2 (for the current 4.2 branch).
Workarounds
Site owners who are unable to upgrade to the new versions can disable or override the corresponding functionality.
ChooseParentView
For ChooseParentView
:
- Disable ModelAdmin for all page models.
- Or provide a custom view via
choose_parent_view_class
, with the custom view overriding theget_form
method.
One of those steps need to be applied for every ModelAdmin
class hooked into Wagtail where the model is a Wagtail Page
or sub-class. Here is an example of implementing the custom ChooseParentView
with patched HTML escaping:
```python from django import forms from django.utils.translation import gettext as _ from wagtail.contrib.modeladmin.views import ChooseParentView from wagtail.contrib.modeladmin.forms import ParentChooserForm
class PatchedPageChoiceField(forms.ModelChoiceField): """PageChoiceField with plain-text breadcrumbs to patch stored XSS.""" def label_from_instance(self, obj): bits = [] for ancestor in ( obj.get_ancestors(inclusive=True).exclude(depth=1).specific(defer=True) ): bits.append(ancestor.get_admin_display_title()) return ' | '.join(bits)
class PatchedParentChooserForm(ParentChooserForm): """ParentChooserForm with custom parent_page to patch stored XSS.""" parent_page = PatchedPageChoiceField( label=_("Parent page"), required=True, empty_label=None, queryset=Page.objects.none(), widget=forms.RadioSelect(), )
class PatchedChooseParentView(ChooseParentView): """ChooseParentView with custom get_form patch stored XSS.""" def get_form(self, request): parents = self.permission_helper.get_valid_parent_pages(request.user) return PatchedParentChooserForm(parents, request.POST or None) ```
InspectView
For InspectView
:
- Remove
inspect_view_enabled=True
or set it to False to disable the view. - Or use
inspect_view_fields
orinspect_view_fields_exclude
to prevent displaying document fields in the views. - Or provide a custom view via
inspect_view_class
, with the custom view overriding theget_document_field_display
method.
One of those steps need to be applied for every ModelAdmin
class hooked into Wagtail where inspect_view_enabled=True
. Here is an example of implementing the custom InspectView
with patched HTML escaping:
```python from django.template.defaultfilters import filesizeformat from django.utils.html import format_html from wagtail.contrib.modeladmin.views import InspectView
class PatchedInspectView(InspectView): """InspectView with override to patch stored XSS vulnerability.""" def get_document_field_display(self, field_name, field): """Render a link to a document""" document = getattr(self.instance, field_name) if document: return format_html( '{} ', document.url, document.title, document.file_extension.upper(), filesizeformat(document.file.size), ) return self.model_admin.get_empty_value_display(field_name) ```
{ "affected": [ { "package": { "ecosystem": "PyPI", "name": "wagtail" }, "ranges": [ { "events": [ { "introduced": "1.5" }, { "fixed": "4.1.4" } ], "type": "ECOSYSTEM" } ] }, { "package": { "ecosystem": "PyPI", "name": "wagtail" }, "ranges": [ { "events": [ { "introduced": "4.2" }, { "fixed": "4.2.2" } ], "type": "ECOSYSTEM" } ] } ], "aliases": [ "CVE-2023-28836" ], "database_specific": { "cwe_ids": [ "CWE-79" ], "github_reviewed": true, "github_reviewed_at": "2023-04-03T17:25:27Z", "nvd_published_at": "2023-04-03T17:15:00Z", "severity": "HIGH" }, "details": "### Impact\n\nA stored cross-site scripting (XSS) vulnerability exists on ModelAdmin views within the Wagtail admin interface. A user with a limited-permission editor account for the Wagtail admin could potentially craft pages and documents that, when viewed by a user with higher privileges, could perform actions with that user\u0027s credentials. The vulnerability is not exploitable by an ordinary site visitor without access to the Wagtail admin, and only affects sites with ModelAdmin enabled.\n\n- For page, the vulnerability is in the \"Choose a parent page\" ModelAdmin view ([`ChooseParentView`](https://docs.wagtail.org/en/stable/reference/contrib/modeladmin/chooseparentview.html#customising-chooseparentview)), available when managing pages via ModelAdmin.\n- For documents, the vulnerability is in the ModelAdmin Inspect view ([`InspectView`](https://docs.wagtail.org/en/stable/reference/contrib/modeladmin/inspectview.html#enabling-customising-inspectview)) when displaying document fields.\n\n### Patches\n\nPatched versions have been released as Wagtail 4.1.4 (for the LTS 4.1 branch) and Wagtail 4.2.2 (for the current 4.2 branch).\n\n### Workarounds\n\nSite owners who are unable to upgrade to the new versions can disable or override the corresponding functionality.\n\n#### `ChooseParentView`\n\nFor [`ChooseParentView`](https://docs.wagtail.org/en/stable/reference/contrib/modeladmin/chooseparentview.html#modeladmin-choose-parent-view-class):\n\n- Disable ModelAdmin for all page models.\n- Or provide a custom view via [`choose_parent_view_class`](https://docs.wagtail.org/en/stable/reference/contrib/modeladmin/chooseparentview.html#id4), with the custom view overriding the `get_form` method.\n\nOne of those steps need to be applied for every `ModelAdmin` class hooked into Wagtail where the model is a Wagtail `Page` or sub-class. Here is an example of implementing the custom `ChooseParentView` with patched HTML escaping:\n\n```python\nfrom django import forms\nfrom django.utils.translation import gettext as _\nfrom wagtail.contrib.modeladmin.views import ChooseParentView\nfrom wagtail.contrib.modeladmin.forms import ParentChooserForm\n\n\nclass PatchedPageChoiceField(forms.ModelChoiceField):\n \"\"\"PageChoiceField with plain-text breadcrumbs to patch stored XSS.\"\"\"\n def label_from_instance(self, obj):\n bits = []\n for ancestor in (\n obj.get_ancestors(inclusive=True).exclude(depth=1).specific(defer=True)\n ):\n bits.append(ancestor.get_admin_display_title())\n return \u0027 | \u0027.join(bits)\n\n\nclass PatchedParentChooserForm(ParentChooserForm):\n \"\"\"ParentChooserForm with custom parent_page to patch stored XSS.\"\"\"\n parent_page = PatchedPageChoiceField(\n label=_(\"Parent page\"),\n required=True,\n empty_label=None,\n queryset=Page.objects.none(),\n widget=forms.RadioSelect(),\n )\n\n\nclass PatchedChooseParentView(ChooseParentView):\n \"\"\"ChooseParentView with custom get_form patch stored XSS.\"\"\"\n def get_form(self, request):\n parents = self.permission_helper.get_valid_parent_pages(request.user)\n return PatchedParentChooserForm(parents, request.POST or None)\n```\n\n#### `InspectView`\n\nFor [`InspectView`](https://docs.wagtail.org/en/stable/reference/contrib/modeladmin/inspectview.html#enabling-customising-inspectview):\n\n- Remove `inspect_view_enabled=True` or set it to False to disable the view.\n- Or use [`inspect_view_fields`](https://docs.wagtail.org/en/stable/reference/contrib/modeladmin/inspectview.html#modeladmin-inspect-view-fields) or [`inspect_view_fields_exclude`](https://docs.wagtail.org/en/stable/reference/contrib/modeladmin/inspectview.html#modeladmin-inspect-view-fields-exclude) to prevent displaying document fields in the views.\n- Or provide a custom view via [`inspect_view_class`](https://docs.wagtail.org/en/stable/reference/contrib/modeladmin/inspectview.html#id12), with the custom view overriding the `get_document_field_display` method.\n\nOne of those steps need to be applied for every `ModelAdmin` class hooked into Wagtail where `inspect_view_enabled=True`. Here is an example of implementing the custom `InspectView` with patched HTML escaping:\n\n```python\nfrom django.template.defaultfilters import filesizeformat\nfrom django.utils.html import format_html\nfrom wagtail.contrib.modeladmin.views import InspectView\n\n\nclass PatchedInspectView(InspectView):\n \"\"\"InspectView with override to patch stored XSS vulnerability.\"\"\"\n def get_document_field_display(self, field_name, field):\n \"\"\"Render a link to a document\"\"\"\n document = getattr(self.instance, field_name)\n if document:\n return format_html(\n \u0027\u003ca href=\"{}\"\u003e{} \u003cspan class=\"meta\"\u003e({}, {})\u003c/span\u003e\u003c/a\u003e\u0027,\n document.url,\n document.title,\n document.file_extension.upper(),\n filesizeformat(document.file.size),\n )\n return self.model_admin.get_empty_value_display(field_name)\n```", "id": "GHSA-5286-f2rf-35c2", "modified": "2024-11-19T16:19:21Z", "published": "2023-04-03T17:25:27Z", "references": [ { "type": "WEB", "url": "https://github.com/wagtail/wagtail/security/advisories/GHSA-5286-f2rf-35c2" }, { "type": "ADVISORY", "url": "https://nvd.nist.gov/vuln/detail/CVE-2023-28836" }, { "type": "WEB", "url": "https://github.com/wagtail/wagtail/commit/5be2b1ed55fd7259dfdf2c82e7701dba407b8b62" }, { "type": "WEB", "url": "https://github.com/wagtail/wagtail/commit/bc84bf9815610cfbf8db3b6050c7ddcbaa4b9713" }, { "type": "WEB", "url": "https://github.com/wagtail/wagtail/commit/eefc3381d37b476791610e5d30594fae443f33af" }, { "type": "WEB", "url": "https://github.com/wagtail/wagtail/commit/ff806ab173a504395fdfb3139eb0a29444ab4b91" }, { "type": "WEB", "url": "https://docs.wagtail.org/en/stable/reference/contrib/modeladmin/chooseparentview.html#customising-chooseparentview" }, { "type": "WEB", "url": "https://docs.wagtail.org/en/stable/reference/contrib/modeladmin/inspectview.html#enabling-customising-inspectview" }, { "type": "WEB", "url": "https://github.com/pypa/advisory-database/tree/main/vulns/wagtail/PYSEC-2023-55.yaml" }, { "type": "PACKAGE", "url": "https://github.com/wagtail/wagtail" }, { "type": "WEB", "url": "https://github.com/wagtail/wagtail/releases/tag/v4.1.4" }, { "type": "WEB", "url": "https://github.com/wagtail/wagtail/releases/tag/v4.2.2" } ], "schema_version": "1.4.0", "severity": [ { "score": "CVSS:3.1/AV:N/AC:H/PR:H/UI:R/S:U/C:H/I:H/A:H", "type": "CVSS_V3" }, { "score": "CVSS:4.0/AV:N/AC:L/AT:P/PR:L/UI:P/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N", "type": "CVSS_V4" } ], "summary": "Wagtail vulnerable to stored Cross-site Scripting attack via ModelAdmin views" }
Sightings
Author | Source | Type | Date |
---|
Nomenclature
- Seen: The vulnerability was mentioned, discussed, or seen somewhere by the user.
- Confirmed: The vulnerability is confirmed from an analyst perspective.
- Exploited: This vulnerability was exploited and seen by the user reporting the sighting.
- Patched: This vulnerability was successfully patched by the user reporting the sighting.
- Not exploited: This vulnerability was not exploited or seen by the user reporting the sighting.
- Not confirmed: The user expresses doubt about the veracity of the vulnerability.
- Not patched: This vulnerability was not successfully patched by the user reporting the sighting.