The Python Package Index (PyPI) repository has introduced a new secure method for publishing packages. This method allows avoiding the need to store fixed passwords and API access tokens in external systems (such as GitHub Actions). The new authentication method is called 'Trusted Publishers' and aims to address the issue of malicious updates that can occur when external systems are compromised, allowing attackers access to predefined passwords or tokens.
The new authentication method is based on the OpenID Connect (OIDC) standard, which uses short-lived authentication tokens exchanged between external services and the PyPI catalog to confirm package publication instead of using traditional login/password combinations or manually generated permanent API access tokens. The 'Trusted Publishers' mechanism has already been implemented for handlers running in GitHub Actions. Future support for Trusted Publishers is also expected for other external services.
Accompanying packages can mark identifiers provided by external OpenID (IdP, OpenID Connect Identity Provider) providers as trusted on the PyPI side. These external services will use these identifiers to request short-lived tokens from PyPI. The generated OpenID Connect tokens verify the association between the project and the handler, allowing PyPI to perform additional metadata verification, such as checking that the published package corresponds to a specific repository. Tokens are not stored, are tied to specific APIs, and automatically expire after a short lifespan.
Additionally, it is worth noting the report by Sonatype, which revealed 6,933 malicious packages in the PyPI directory in March 2023. Since 2019, the total number of identified malicious packages in PyPI has exceeded 115,000. Most of these malicious packages disguise themselves as popular libraries through typosquatting (using similar names differing by individual characters, such as exampl instead of example, djangoo instead of django, pyhton instead of python, etc.) — attackers rely on inattentive users who make typographical errors or do not notice the differences in names when searching. Malicious actions usually involve sending confidential data found on the local system as a result of identifying typical files with passwords, access keys, cryptocurrency wallets, tokens, session cookies, and other sensitive information.
Source: opennet.ru
