VAITP Dataset

← Back to the dataset

CVE-2020-24584

Incorrect permissions in Django 2.2.16, 3.0.10, and 3.1.1 cache directories with Python 3.7

  • CVSS 7.5
  • CWE-276 Incorrect Default Permissions
  • Design Defects
  • Local

An issue was discovered in Django 2.2 before 2.2.16, 3.0 before 3.0.10, and 3.1 before 3.1.1 (when Python 3.7+ is used). The intermediate-level directories of the filesystem cache had the system's standard umask rather than 0o077.

CVSS base score
7.5
Published
2020-09-01
OWASP
A05 Security Misconfiguration
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Design Defects
Subcategory
Security Misconfigurations
Accessibility scope
Local
Impact
Unauthorized Access
Affected component
Django
Fixed by upgrading
Yes

Solution

Update Django to version 2.2.16, 3.0.10, or 3.1.1.

Vulnerable code sample

import os
import tempfile
from django.core.cache import FileBasedCache

class InsecureFileBasedCache(FileBasedCache):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._create_cache_directory()

    def _create_cache_directory(self):
        # Create the cache directory with the system's standard umask
        os.makedirs(self.location, exist_ok=True)

# Usage
cache = InsecureFileBasedCache('my_cache', location=tempfile.gettempdir())

Patched code sample

import os
import tempfile
from django.core.cache import FileBasedCache

class SecureFileBasedCache(FileBasedCache):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._set_secure_permissions()

    def _set_secure_permissions(self):
        # Set the umask to 0o077 to ensure that the intermediate directories
        # have restrictive permissions
        original_umask = os.umask(0o077)
        try:
            # Create the cache directory with secure permissions
            os.makedirs(self.location, exist_ok=True)
        finally:
            os.umask(original_umask)

# Usage
cache = SecureFileBasedCache('my_cache', location=tempfile.gettempdir())

Published fix

Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.

Cite this entry

@misc{vaitp:cve202024584,
  title        = {{Incorrect permissions in Django 2.2.16, 3.0.10, and 3.1.1 cache directories with Python 3.7}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2020},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2020-24584},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2020-24584/}}
}

Download this entry as JSON Download the whole dataset

Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.