Skip to content

Security and Internals

Reporting security vulnerabilities

Do not report security issues in public forums or issue trackers.

To read the most up-to-date version of PyPI's security policy, including directions for reporting security issues, please visit https://pypi.org/security.

PyPI as a target

Unfortunately, PyPI's open and accessible nature, combined with its widespread use, makes it a high-profile target for hackers, spammers, and other malicious actors. They attempt to compromise PyPI and our users in several ways:

Software supply chain attacks

By injecting malicious code into popular packages, attackers can compromise the software supply chain. This allows them to distribute malware to a vast number of developers and end-users who unwittingly install the compromised packages. These attacks can lead to data theft, system compromise, and the installation of malware like remote access trojans (RATs) and information stealers.

Phishing campaigns

Attackers may impersonate PyPI or its maintainers in emails or on other platforms to trick users into revealing their login credentials. For example, a recent phishing campaign lured PyPI users to a fake site at pypj.org, using a j to impersonate the i in pypi.org, in order to steal their credentials.

Account takeover via expired domains

Attackers may attempt to take over accounts by exploiting expired email domains. By registering a domain that was previously associated with a user's PyPI account, an attacker can reactivate the email address to initiate a password reset. Attackers identify potential targets by scanning the email metadata of published packages. See our blog post on preventing domain resurrection attacks for more information.

Typosquatting

Attackers upload packages with names that are common misspellings of popular libraries. They rely on developers making a typo to accidentally install the malicious version. In March 2024, a large-scale typosquatting campaign led to PyPI temporarily halting new user and project registrations to mitigate the threat.

Spam

Spammers return to PyPI with some regularity hoping to place their search engine optimized (SEO) phishing, scam, and click-farming content on the site. Since PyPI allows search engines to index a project's long description and other metadata, and has a strong search reputation, it is a prime target.

The PyPI team uses the PyPI blog to publicly report on security compromises and remediations.

PyPI security features

PyPI provides a range of security features to defend our users and the Python ecosystem from bad actors:

Account security

Mandatory two-factor authentication (2FA)

To enhance account security, PyPI mandates 2FA for all users. This requires all users to authenticate with a second form of verification (in addition to an account password) such as a code from an authenticator app or a physical security key. See Two-Factor Authentication for more information.

Verified email address

To perform certain actions, such as registering a new project, users must have a verified email address (proving that they own the email address). Verified email addresses are also required to receive password-reset emails. See Email address verification for more information. PyPI also:

  • Maintains a blocklist of domains flagged for spam or other abuse, using that list to reject email addresses from those domains.
  • Checks the reputation of email addresses on account registration, or when a user adds an email address to their account. Addresses identified as disposable or temporary are rejected, and domains identified as disposable providers are added to the blocklist. See our blog post on email reputation checks and account registration limits for more information.
  • Checks that email domains are valid on account registration, or when a user adds or changes the email addresses associated with their account.
  • Periodically scans for verified emails with expired email domains or MX records, removing verification from those emails vulnerable to attack. See our blog post on preventing domain resurrection attacks for more information.

Phishing awareness

PyPI implements email authentication standards (SPF, DKIM, and DMARC) to help prevent phishing by allowing mail servers to verify the authenticity of emails sent from PyPI.org. However, because the enforcement of these standards is the responsibility of the receiving mail server, fraudulent emails may still reach a user's inbox. Users should remain cautious of suspicious links and always verify they are on the official pypi.org domain before entering credentials. See this incident report for more information.

Publishing security

Trusted Publishing

This is the most secure and recommended method for publishing packages. It uses the OpenID Connect (OIDC) standard to allow a CI/CD provider (like GitHub Actions) to securely obtain short-lived API tokens and publish a package to PyPI. See Trusted Publishing for more information. This approach:

  • Removes the need for project maintainers to manually manage or store secrets, eliminating the risk of a long-lived API token being leaked
  • Is more secure because build workflows can be protected by repository-level controls like branch protection and required reviews
  • Provides a visible audit trail if there is any attempt to maliciously alter the build workflow (as this typically requires a public commit)
  • Supports attestations so package consumers can verify the publishing identity. The official PyPA GitHub publishing action generates and uploads these by default when using Trusted Publishing (unless disabled).

API tokens

For manual uploads or for services that do not yet support Trusted Publishing, API tokens serve as an alternative to using an account password for authentication. PyPI API tokens can be scoped to specific projects, limiting the potential damage if a token is ever compromised. See Using an API token for more information.

Threat response and automated protections

Malware reporting

PyPI relies on its users and the wider security community to help identify and report malicious packages. See our post on malware reporting for more information. Users can report malware:

  • Via PyPI.org: Suspicious packages should be reported using the "Report project as malware" link on a project's security tab
  • Via API (Beta): PyPI provides a malware reporting API. This API is currently in beta, and users can apply to participate by completing this Google Form.

Project quarantine

Projects that are flagged as malicious are placed in "quarantine." A quarantined project cannot be downloaded, and its owners cannot modify it. This immediately neutralizes the threat while the report is reviewed. See our blog post on project quarantine for more information.

Temporarily disabling features

During a large-scale spam or malware attack, or another threat to PyPI, administrators can temporarily disable some features site-wide to contain the threat. These include:

  • New user registration (see account registration limits)
  • New project registration
  • New package uploads, or in severe cases, all writes via a full read-only mode (see publishing troubleshooting)
  • Project deletion
  • Trusted Publishing, either for all providers or for a single provider (e.g. GitHub or GitLab)

These restrictions apply to all users and are not specific to your account or project. The PyPI status page provides updates and the reason for the intervention during any such event.

Typosquatting protection

To combat typosquatting, PyPI:

  • Normalizes project names — removing separators like ., _, and -, and treating easily-confused characters (like l, i, and 1, or o and 0) as identical. It then compares the normalized name against existing projects, and rejects any new name that collides.
  • Compares names against Python standard library module names, and rejects any new name that matches.

These checks don't catch every typosquat, so always verify you're installing the exact package you intend. See Choosing a project name for more information.

Preventing ZIP confusion attacks

Python package "wheels" (or "binary distributions") are actually a ZIP archive in disguise. PyPI rejects ZIPs constructed to exploit ZIP confusion attacks. See this blog post for more information.

Internals

What powers PyPI?

PyPI is powered by Warehouse and by a variety of tools and services provided by our generous sponsors. For more information, see the:

How can I get a list of PyPI's IP addresses?

All traffic is routed through our global CDN, which lists their public IP addresses here: https://api.fastly.com/public-ip-list.

More information about this list can be found here: https://docs.fastly.com/en/guides/accessing-fastlys-ip-ranges.