CVE-2021-28658: Django Path Traversal Vulnerability

MODERATE
Advisory Identifier: GHSA-xgxc-v2qg-chmh
CVSS 5.3
CWE-22
Published
Advisory Summary

CVE-2021-28658 is a MODERATE (CVSS 5.3) path traversal vulnerability (CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')) affecting Django libraries in the PyPI ecosystem. The issue involves directory traversal in django. Remediation is available by upgrading affected packages to version 2.2.20, 3.0.14, 3.1.8.

CVE-2021-28658 at a Glance

CVE Identifier CVE-2021-28658
GHSA Identifier GHSA-xgxc-v2qg-chmh
Severity MODERATE
CVSS v3.1 Base Score 5.3
CWE Classification CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Affected Product Django
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 5.3

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:L/I:N/A:N).

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 Low (C:L)
Integrity None (I:N)
Availability None (A:N)

How to Fix CVE-2021-28658

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

Django fixed: 2.2.20
pip install Django>=2.2.20
Django fixed: 3.0.14
pip install Django>=3.0.14
Django fixed: 3.1.8
pip install Django>=3.1.8
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 Django

How to Check if You Are Affected

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

pip show Django

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

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

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where the product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory. In Django, 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

In Django 2.2 before 2.2.20, 3.0 before 3.0.14, and 3.1 before 3.1.8, MultiPartParser allowed directory traversal via uploaded files with suitably crafted file names. Built-in upload handlers were not affected by this vulnerability.

CVE-2021-28658 Affected Django Versions

3 component(s)
Fixed Versions:
2.2.203.0.143.1.8
Product / Package Ecosystem Affected Versions Fixed Version
Django
PyPI
≥ 2.2a1
< 2.2.20
2.2.20
Django
PyPI
≥ 3.0a1
< 3.0.14
3.0.14
Django
PyPI
≥ 3.1a1
< 3.1.8
3.1.8

References

Frequently Asked Questions

What is CVE-2021-28658?
CVE-2021-28658 is a security vulnerability in Django involving Directory Traversal in Django under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Which Django versions are affected?
Affected versions include releases prior to 2.2.20, 3.0.14, 3.1.8 across affected packages: Django.
What version fixes CVE-2021-28658?
Upgrading to 2.2.20, 3.0.14, 3.1.8 (or the latest patched release for your respective branch) resolves the vulnerability.
Is Django affected?
Yes, Django is affected in releases prior to 2.2.20, 3.0.14, 3.1.8. Upgrade your dependency to 2.2.20, 3.0.14, 3.1.8 or later.
What is the CVSS score of CVE-2021-28658?
CVE-2021-28658 has a CVSS v3.1 base score of 5.3 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N.
What CWE is associated with CVE-2021-28658?
CVE-2021-28658 is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') (The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.).
How can I check PyPI dependencies for CVE-2021-28658?
Run the dependency tree command: 'pip show Django'. 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-xgxc-v2qg-chmh",
  "modified" : "2024-09-20T15:47:26Z",
  "published" : "2021-04-08T18:11:48Z",
  "aliases" : [ "CVE-2021-28658" ],
  "summary" : "Directory Traversal in Django",
  "details" : "In Django 2.2 before 2.2.20, 3.0 before 3.0.14, and 3.1 before 3.1.8, MultiPartParser allowed directory traversal via uploaded files with suitably crafted file names. Built-in upload handlers were not affected by this vulnerability.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:L/VI:N/VA:N/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "Django"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.2a1"
      }, {
        "fixed" : "2.2.20"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "Django"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "3.0a1"
      }, {
        "fixed" : "3.0.14"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "Django"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "3.1a1"
      }, {
        "fixed" : "3.1.8"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-28658"
  }, {
    "type" : "WEB",
    "url" : "https://docs.djangoproject.com/en/3.1/releases/security"
  }, {
    "type" : "ADVISORY",
    "url" : "https://github.com/advisories/GHSA-xgxc-v2qg-chmh"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/django/django"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/django/PYSEC-2021-6.yaml"
  }, {
    "type" : "WEB",
    "url" : "https://groups.google.com/g/django-announce/c/ePr5j-ngdPU"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2021/04/msg00008.html"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/ZVKYPHR3TKR2ESWXBPOJEKRO2OSJRZUE"
  }, {
    "type" : "WEB",
    "url" : "https://pypi.org/project/Django"
  }, {
    "type" : "WEB",
    "url" : "https://security.netapp.com/advisory/ntap-20210528-0001"
  }, {
    "type" : "WEB",
    "url" : "https://www.djangoproject.com/weblog/2021/apr/06/security-releases"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-22" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-04-08T18:11:26Z",
    "nvd_published_at" : "2021-04-06T15:15:00Z"
  }
}