Medium

Malicious package may avoid detection in python auditing

  • Disclosed: 23.03.2020
  • Updated: 11.10.2026 13:19

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

  1. 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.

Affected software

Click a technology to see all vulnerabilities affecting it.

PlatformPackageVulnerable versionsFixed in
Python (PyPI) safety < 1.9.0 1.9.0

References

CVSS score 5/10
CVSS vector
CVSS:3.1/AV:L/AC:H/PR:H/UI:R/S:C/C:N/I:H/A:N
Weakness (CWE)
CWE-807
Platform
Python (PyPI)
Package
safety
Disclosed
23.03.2020
Updated
11.10.2026 13:19

Sources and licenses

OSV / GitHub Advisory Database - PYSEC-2020-101 - PyPA Advisory Database; CC BY 4.0

OSV / GitHub Advisory Database - GHSA-7q25-qrjw-6fg2 - CC BY 4.0

Vulnerability history: safety

All published vulnerabilities of this package (Python (PyPI)), newest first. Shows whether this is a one-off slip or a package that needs watching.

This is the only known vulnerability of this package.

Know which vulnerabilities affect your application

With the DockRay integration and software inventory enabled, DockRay checks reported component versions against known vulnerabilities and notifies you about confirmed matches. Coverage depends on the supported technology and available advisory data.

Connect your application
DockRay newsletter

Application security in your inbox

Important vulnerabilities, actionable guidance and practical advice for your applications. Choose your technologies and follow what matters to your project.

  • A daily digest of new vulnerabilities, critical ones included.
  • Notifications about important updates.
  • Practical advice on application security and monitoring.

Leave empty to receive updates for every technology.

Free to subscribe. Unsubscribe with one click in any email.