CVE-2021-42771: Babel Path Traversal Vulnerability

HIGH
Advisory Identifier: GHSA-h4m5-qpfp-3mpv
CVSS 7.8
CWE-22
Published
Advisory Summary

CVE-2021-42771 is a HIGH (CVSS 7.8) path traversal vulnerability (CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')) affecting Babel libraries in the PyPI ecosystem. The issue involves directory traversal in babel. Remediation is available by upgrading affected packages to version 2.9.1.

CVE-2021-42771 at a Glance

CVE Identifier CVE-2021-42771
GHSA Identifier GHSA-h4m5-qpfp-3mpv
Severity HIGH
CVSS v3.1 Base Score 7.8
CWE Classification CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Affected Product Babel
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 7.8

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

Attack Vector Local (AV:L)
Attack Complexity Low (AC:L)
Privileges Required Low (PR:L)
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-2021-42771

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

babel fixed: 2.9.1
pip install babel>=2.9.1
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 babel

How to Check if You Are Affected

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

pip show babel

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

Note: The pip show babel 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 Babel, 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

Babel.Locale in Babel before 2.9.1 allows attackers to load arbitrary locale .dat files (containing serialized Python objects) via directory traversal, leading to code execution.

CVE-2021-42771 Affected Babel Versions

1 component(s)
Fixed Versions:
2.9.1
Product / Package Ecosystem Affected Versions Fixed Version
babel
PyPI
< 2.9.1
2.9.1

References

Frequently Asked Questions

What is CVE-2021-42771?
CVE-2021-42771 is a security vulnerability in Babel involving Directory Traversal in Babel under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Which Babel versions are affected?
Affected versions include releases prior to 2.9.1 across affected packages: babel.
What version fixes CVE-2021-42771?
Upgrading to 2.9.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is babel affected?
Yes, babel is affected in releases prior to 2.9.1. Upgrade your dependency to 2.9.1 or later.
What is the CVSS score of CVE-2021-42771?
CVE-2021-42771 has a CVSS v3.1 base score of 7.8 (HIGH) with vector string CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2021-42771?
CVE-2021-42771 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-42771?
Run the dependency tree command: 'pip show babel'. 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-h4m5-qpfp-3mpv",
  "modified" : "2024-09-12T20:56:02Z",
  "published" : "2021-10-21T17:49:59Z",
  "aliases" : [ "CVE-2021-42771" ],
  "summary" : "Directory Traversal in Babel",
  "details" : "Babel.Locale in Babel before 2.9.1 allows attackers to load arbitrary locale .dat files (containing serialized Python objects) via directory traversal, leading to code execution.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "babel"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.9.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-42771"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/python-babel/babel/pull/782"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/python-babel/babel/commit/412015ef642bfcc0d8ba8f4d05cdbb6aac98d9b3"
  }, {
    "type" : "ADVISORY",
    "url" : "https://github.com/advisories/GHSA-h4m5-qpfp-3mpv"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/babel/PYSEC-2021-421.yaml"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/python-babel/babel"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2021/10/msg00018.html"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts/2021/10/msg00040.html"
  }, {
    "type" : "WEB",
    "url" : "https://www.debian.org/security/2021/dsa-5018"
  }, {
    "type" : "WEB",
    "url" : "https://www.tenable.com/security/research/tra-2021-14"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-22" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-10-21T14:33:55Z",
    "nvd_published_at" : "2021-10-20T21:15:00Z"
  }
}