Implement --index-strategy to mitigate dependency confusion (#8606)#13773
Implement --index-strategy to mitigate dependency confusion (#8606)#13773Ashutosh0x wants to merge 16 commits intopypa:mainfrom
Conversation
|
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
|
Hi @Ashutosh0x thanks for the PR, please be aware reviews can be quite slow due to maintainers only being able to volunteer their spare time to pip. That said, I would like you to explicitly explain the design here:
To be clear you don't have to match uv, but given it's set a precedent it should be understood if not why not. If the design is agreed on there will need to be at least an update to the user guide, as well as unit and functional tests. I also think I prefer uv's choice of have an option that can take different values, rather than a boolean, this will allow users to explicitly choose new or old behavior, add new options in the future, and potentially change the default. P.S The Windows failures for |
|
Thanks for the review @notatallshaw! Regarding the design questions:
Plan:
I'll push these changes shortly! |
|
Also, for |
|
|
||
| # Custom PR/Issue body files | ||
| ISSUE_BODY.md | ||
| PR_BODY.md | ||
| PR_FIX_PLAN.md |
There was a problem hiding this comment.
Please don't make changes to the repo's .gitignore, if you need to git ignore local files you should create your own user level git ignore, e.g. https://dev.to/fronkan/a-personal-gitignore-even-for-a-single-repository-4o7h
This PR implements the
--index-strategyfeature to mitigate dependency confusion attacks, addressing #8606.Summary
--index-strategy: Controls how pip selects packages from multiple indexes.best-match(default): Standard pip behavior. Searches all indexes for the highest version.first-match: Prioritizes indexes in the order they are provided (--index-urlthen--extra-index-url). The search stops at the first index that yields a match.Motivation
The current "Version Priority" behavior exposes users to Dependency Confusion attacks. An attacker can upload a higher version of a private package name to a public repository, and pip will prioritize it. This feature provides a mechanism for users to enforce index isolation by stopping the search once a match is found.
Design Details
find-linksare collected first. Then, we iterate through--index-urland--extra-index-urlin order.first-matchmode, the search stops as soon as one index URL returns candidates.