How to get pwned with — extra-index-url
The pip package manager with the --extra-index-url flag searches both a private index and PyPI, and installs the highest version found. An attacker can publish a malicious package with the same name and a higher version to PyPI, causing it to be installed instead of the intended private package.
Published on infosecwriteups.com
Python’s built-in pip package manager is unsafe when used with the --extra-index-url flag (there are other dangerous variants too). An attacker can publish a malicious package with the same name and a higher version to PyPI, and their package will be installed.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely, pip's dependency resolution with --extra-index-url does not prioritise the specified private index over PyPI, so it selects the highest version across all indexes.
Impact
An attacker could execute arbitrary code on the victim's machine or infrastructure by installing a malicious package, potentially stealing credentials or installing a backdoor.
What the attacker needed
Pip with --extra-index-url; attacker can publish to PyPI; victim installs package
The fix
Avoid using --extra-index-url with pip and --index-strategy with uv; instead, use a private registry with a PyPI pass-through as the only index.
How it was found
- Publish a safe package version 0.0.1 to a private index.
- Publish a malicious package with the same name and version 1.0.0 to PyPI.
- Run pip install with --extra-index-url pointing to the private index.
- Observe that the malicious version 1.0.0 is installed.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
When you install a Python package, pip can be told to look in more than one place. If a bad person puts a package with the same name but a higher version number in the public place, pip will pick that one. This means you could end up running code from an attacker without knowing.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.