Vulnerabilities in pkg:pypi/safety

PACKAGE
Advisory Identifier: GHSA-7q25-qrjw-6fg2
Advisory Summary

CVE-2020-5252 is a MODERATE (CVSS 5.0) malicious package may avoid detection vulnerability (CWE-807: Reliance on Untrusted Inputs in a Security Decision) affecting Safety libraries in the PyPI ecosystem. The issue involves malicious package may avoid detection in python auditing. Remediation is available by upgrading affected packages to version 1.9.0.

1 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:pypi/safety

1 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:pypi/safety. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-7q25-qrjw-6fg2 CVE-2020-5252 MODERATE Malicious package may avoid detection in python auditing

CVE-2020-5252 at a Glance

CVE Identifier CVE-2020-5252
GHSA Identifier GHSA-7q25-qrjw-6fg2
Severity MODERATE
CVSS v3.1 Base Score 5.0
CWE Classification CWE-807: Reliance on Untrusted Inputs in a Security Decision
Affected Product Safety
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 5.0

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

Attack Vector Local (AV:L)
Attack Complexity High (AC:H)
Privileges Required High (PR:H)
User Interaction Required (UI:R)
Scope Changed (S:C)
Confidentiality None (C:N)
Integrity High (I:H)
Availability None (A:N)

How to Fix CVE-2020-5252

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

safety fixed: 1.9.0
pip install safety>=1.9.0
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 safety

How to Check if You Are Affected

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

pip show safety

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

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

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-807: Reliance on Untrusted Inputs in a Security Decision, where the product uses a protection mechanism that relies on the existence or values of an input, but the input can be modified by an untrusted actor in a way that bypasses the protection mechanism. In Safety, 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

# Python Auditing Vulnerability Demonstrates how a malicious package can insert a load-time poison pill to avoid detection by tools like Safety. Tools that are designed to find vulnerable packages can not ever run in the same python environment that they are trying to protect. ## Usage Install `safety`, `insecure-package`, and this package with pip in the same python environment. Order doesn't matter. 1. pip install safety 2. pip install insecure-package 3. pip install dist/malicious-0.1-py3-none-any.whl Run the check 4. `safety check` You should see both `Running my modified safety.check` and that `insecure-package` is not listed in the results! ## How it Works Everything in Python is mutable. The trick is getting some code to run at interpreter load time in order to do some patching. 1. When you install this package, the `setup.py` settings installs a `malicious.pth` file to your `site-packages` directory. 2. The `malicious.pth` file gets loaded anytime Python starts, which in turn imports our `malicious` package. 3. The `malicious/__init__.py` patches the safety library with a custom function to avoid detection.

CVE-2020-5252 Affected Safety Versions

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

References

Frequently Asked Questions

What is CVE-2020-5252?
CVE-2020-5252 is a security vulnerability in Safety involving Malicious package may avoid detection in python auditing under CWE-807: Reliance on Untrusted Inputs in a Security Decision.
Which Safety versions are affected?
Affected versions include releases prior to 1.9.0 across affected packages: safety.
What version fixes CVE-2020-5252?
Upgrading to 1.9.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is safety affected?
Yes, safety is affected in releases prior to 1.9.0. Upgrade your dependency to 1.9.0 or later.
What is the CVSS score of CVE-2020-5252?
CVE-2020-5252 has a CVSS v3.1 base score of 5.0 (MODERATE) with vector string CVSS:3.1/AV:L/AC:H/PR:H/UI:R/S:C/C:N/I:H/A:N.
What CWE is associated with CVE-2020-5252?
CVE-2020-5252 is classified under CWE-807: Reliance on Untrusted Inputs in a Security Decision (The product uses a protection mechanism that relies on the existence or values of an input, but the input can be modified by an untrusted actor in a way that bypasses the protection mechanism.).
How can I check PyPI dependencies for CVE-2020-5252?
Run the dependency tree command: 'pip show safety'. 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-7q25-qrjw-6fg2",
  "modified" : "2024-10-21T21:06:25Z",
  "published" : "2020-03-24T15:07:56Z",
  "aliases" : [ "CVE-2020-5252" ],
  "summary" : "Malicious package may avoid detection in python auditing",
  "details" : "# Python Auditing Vulnerability\n\nDemonstrates how a malicious package can insert a load-time poison pill to avoid detection by tools like Safety.\n\nTools that are designed to find vulnerable packages can not ever run in the same python environment that they are trying to protect.\n\n## Usage\n\nInstall `safety`, `insecure-package`, and this package with pip in the same python environment. Order doesn&amp;#39;t matter.\n\n1. pip install safety\n2. pip install insecure-package\n3. pip install dist/malicious-0.1-py3-none-any.whl\n\nRun the check\n\n4. `safety check`\n\nYou should see both `Running my modified safety.check` and that `insecure-package` is not listed in the results!\n\n\n## How it Works\n\nEverything in Python is mutable. The trick is getting some code to run at interpreter load time in order to do some patching.\n\n1. When you install this package, the `setup.py` settings installs a `malicious.pth` file to your `site-packages` directory.\n2. The `malicious.pth` file gets loaded anytime Python starts, which in turn imports our `malicious` package.\n3. The `malicious/__init__.py` patches the safety library with a custom function to avoid detection.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:L/AC:H/PR:H/UI:R/S:C/C:N/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "safety"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.9.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/pyupio/safety/security/advisories/GHSA-7q25-qrjw-6fg2"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2020-5252"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/akoumjian/python-safety-vuln"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/safety/PYSEC-2020-101.yaml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/pyupio/safety"
  }, {
    "type" : "WEB",
    "url" : "https://mulch.dev/blog/CVE-2020-5252-python-safety-vuln"
  }, {
    "type" : "WEB",
    "url" : "https://pyup.io/posts/patched-vulnerability"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-807" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2020-03-23T23:07:41Z",
    "nvd_published_at" : null
  }
}