Learn Python with Talk Python's 270 hours of courses

PyPI Security

Episode #435, published Wed, Oct 25, 2023, recorded Mon, Sep 18, 2023

Do you worry about your developer / data science supply chain safety? All the packages for the Python ecosystem are much of what makes Python awesome. But the are also a bit of an open door to your code and machine. Luckily the PSF is taking this seriously and hired Mike Fiedler as the full time PyPI Safety & Security Engineer (not to be confused with the Security Developer in Residence staffed by Seth Michael Larson). Mike is here to give us the state of the PyPI security and plans for the future.

Watch this episode on YouTube
Play on YouTube
Watch the live stream version

Episode Deep Dive

Guests Introduction and Background

Mike Fiedler is the full-time PyPI Safety & Security Engineer at the Python Software Foundation (PSF). With over 30 years of software and systems engineering experience at companies like Datadog, Warby Parker, and MongoDB, Mike focuses on strengthening PyPI's security to protect the Python ecosystem from malicious packages and other supply chain threats. He also coordinates with many of the PSF’s security partners to ensure PyPI can respond rapidly to emerging issues.

What to Know If You’re New to Python

If you're new to Python and want to understand this conversation about securing packages, here are a few essentials:

  • It’s common to install Python libraries with tools like pip, which download code from PyPI.org.
  • Take a moment to double-check the library names to avoid installing lookalike or typo-squatted packages.
  • Learn how virtual environments (via venv or other tools) help isolate and manage project dependencies safely.

Key Points and Takeaways

1) PyPI’s Upcoming 2FA Mandate

PyPI is requiring all publishers to enable two-factor authentication (2FA) by the end of 2023. This move helps safeguard package uploads from account hijacking and password reuse vulnerabilities. While 2FA won’t block every kind of phishing attack, it significantly raises the bar for attackers who rely on leaked or stolen credentials.

2) Role of the PSF and Funding for Security

Mike explained how the PSF’s small full-time staff, aided by grants from AWS and others, can now focus directly on PyPI security issues. This includes continuous monitoring, rapid response to malicious packages, and building new features like organizations and enhanced malware reporting.

3) PyPI's Scale and Usage Stats

PyPI hosts nearly half a million projects and over 4 million releases, with over 740,000 user accounts. Mike noted that PyPI’s sheer size means any popular Python library can quickly reach millions of developers, making secure operations essential.

  • Links and Tools:
    • Libraries.io – A resource for statistics on packages across ecosystems

4) Supply Chain Attacks and Typo-Squatting

A big risk in open-source ecosystems is malicious actors uploading “typo-squatted” or misleading packages (e.g., misspelling something like “Django” as “Dangu”). Attackers aim to trick users into installing malware by making package names look familiar or only slightly changed.

5) Trusted Publishers with GitHub Actions

PyPI rolled out “trusted publishers,” using OpenID Connect to grant short-lived tokens to CI/CD services (like GitHub Actions) instead of manually storing long-lived API keys. This eliminates a large class of token-leak vulnerabilities and automatically verifies where the package build originates.

6) Collaborating with Security Researchers

Mike highlighted how PyPI depends on security firms and volunteer researchers who constantly scan new packages, looking for suspicious patterns. Quick removal of newly flagged malicious uploads is a top priority, with PyPI often acting within an hour of a verified report.

7) Human Factor in Security

Both Mike and Michael emphasized that “you, the human, are the best defender.” Phishing, domain expiration takeovers, and reusing passwords all remain major sources of compromise. Using password managers, scanning logs for suspicious activity, and employing mindful security practices go a long way to preventing attacks.

8) Testing and Essential Tools

On the testing side, libraries like pytest remain central to Python’s developer culture. Plugins such as pytest-icdiff can improve clarity when comparing large data structures. The conversation also mentioned how scanning Python packages and checking for vulnerabilities should be part of standard development and testing workflows.

Interesting Quotes and Stories

  • On security trade-offs: “The most secure computer is one that’s powered off and buried in concrete—useless, but perfectly safe.”
  • Human vigilance: “You, the human, are the best defender. Use your logic—don’t just click at things mindlessly.”
  • Typo-squatting hazard: “I can’t prevent anyone from making a typo. But I can help remove packages once we know they’re malicious.”

Key Definitions and Terms

  • 2FA (Two-Factor Authentication): Adds a second layer of identity verification, often using a one-time passcode or security key, in addition to a password.
  • Typo-Squatting: Uploading malicious packages under names resembling popular packages (e.g., reqests for requests) to trick users who make spelling errors.
  • Trusted Publishers (PyPI): A mechanism allowing short-lived CI/CD tokens to publish packages without storing permanent credentials.
  • OpenID Connect: An identity layer on top of OAuth 2.0 used by PyPI for its trusted publisher feature, verifying a build environment’s identity.

Learning Resources

Below are a few in-depth learning materials to deepen your Python skills and better manage dependencies and security:

  • Managing Python Dependencies: Learn how to handle Python dependencies effectively, avoid version conflicts, and understand best practices for safe package usage.

  • Modern Python Projects: Covers the entire Python project lifecycle, from setting up a project structure to CI/CD, testing, and deployment—excellent for building secure, well-managed applications.

Overall Takeaway

Python’s ecosystem is thriving due to PyPI’s ease of publishing and installing packages. However, with so many packages and contributors, security can’t be taken for granted. The PSF and dedicated engineers like Mike Fiedler are working diligently—through 2FA, rapid malware takedowns, and features like trusted publishers—to protect the Python community. Staying vigilant yourself is key: use secure practices, enable 2FA, and always double-check what you’re installing.

Links from the show

Mike on Twitter: @mikefiedler
Mike on Mastodon: @miketheman@hachyderm.io

Supply Chain examples
SolarWinds: csoonline.com
XcodeGhost: wikipedia.org
Google Ad Malware: medium.com

PyPI: pypi.org
OWASP Top 10: owasp.org
Trusted Publishers: docs.pypi.org
libraries.io: libraries.io
GitHub Full 2FA: github.blog
Mike's Latest Blog Post: blog.pypi.org
pprintpp package: github.com
ICDiff: github.com
Watch this episode on YouTube: youtube.com
Episode transcripts: talkpython.fm

--- Stay in touch with us ---
Subscribe to Talk Python on YouTube: youtube.com
Talk Python on Bluesky: @talkpython.fm at bsky.app
Talk Python on Mastodon: talkpython
Michael on Bluesky: @mkennedy.codes at bsky.app
Michael on Mastodon: mkennedy

Talk Python's Mastodon Michael Kennedy's Mastodon