fix(auth): Pipfile creds win netrc; expand env vars in pylock sources (#6670)#6671
Merged
Conversation
…#6670) GHSA-8xgg-v3jj-95m2 moved credentials off pip's argv onto a merged netrc, but the new ``write_credentials_netrc`` writes our Pipfile-derived machine blocks BEFORE appending the user's existing netrc. Python's ``netrc.authenticators()`` returns the LAST matching entry for a host, so any stale system entry for the same host silently overrode the freshly-expanded creds — exactly the symptom of gh-6670 (env-var creds in ``[[source]]`` fail to authenticate after the 2026.6.1 upgrade). Reverse the order so the user's existing netrc lands first and our blocks win the tie-break. Defensively, the ``pylock.toml`` reader now runs ``expand_url_credentials`` over its sources too, mirroring ``Lockfile.load``; without this, users with ``[pipenv] use_pylock = true`` would see env-var auth silently fall through as literal ``${VAR}`` tokens. Add unit regression tests for both paths. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #6670 — restores authentication to private indexes when
[[source]]URLs use environment-variable placeholders, regressed in 2026.6.1 by the GHSA-8xgg-v3jj-95m2 fix.write_credentials_netrcwrote our Pipfile-derivedmachineblocks BEFORE the appended existing user netrc. Python'snetrc.authenticators()returns the LAST matching entry, so any stale system entry for the same host silently overrode the freshly-expanded creds. Reverse the order so our blocks come last and win the tie-break.PylockFile.convert_to_pipenv_lockfileassignedself.data[\"sources\"]raw, dropping env-var expansion on the[pipenv] use_pylock = truepath. Mirror the legacyLockfile.loadbehavior by runningexpand_url_credentialsover each source URL.Test plan
pytest tests/unit/test_credential_safety.py tests/unit/test_pylock.py(37 passed)pytest tests/unit/test_utils.py tests/unit/test_lockfile.py tests/unit/test_pep691_client.py tests/unit/test_resolver_auth.py(broader sweep, 373 passed)test_write_credentials_netrc_pipfile_wins_over_existing_system_netrctest_write_credentials_netrc_from_env_var_expanded_urltest_convert_to_pipenv_lockfile_expands_env_vars_in_source_urls🤖 Generated with Claude Code