Practical technical guides / Recent development

uv 0.13.11 Sends the Credential for the Most Specific Index Path

uv 0.13.11 picks the credential with the longest matching path prefix. A local index test shows 0.13.10 sending the parent credential and failing with 401.

By Sandeep Belgavi · Published 2026-12-02

Longest matching path prefix wins
Original explanatory diagram; synthetic values where shown.

uv 0.13.11 picks the credential with the longest matching path prefix. A local index test shows 0.13.10 sending the parent credential and failing with 401.

The change in one line

uv 0.13.11 was released on 1 December 2026. Its bug fix list includes one line that matters to anyone who installs Python packages from more than one private index on the same host: "Select credentials from the most specific matching URL path prefix". The change comes from pull request 23456, merged on 30 November, titled "Prefer the longest matching URL prefix in the credential cache".

The situation it fixes is common in companies that host several package repositories behind one server. A team repository lives at /team and a more restricted repository at /team/private/simple, each with its own user name and password. Before the fix, uv could send the credential for /team to a URL under /team/private, the server answered 401 Unauthorized, and the install failed with an error that looked like a wrong password. The password was right; it was the wrong one for that path.

How uv chooses a credential

uv keeps an in-memory cache of credentials per URL while it runs. When it sees an index URL with a user name and password in it, or reads them from a netrc file or a keyring, it stores them under that URL. Before each request, the authentication middleware asks the cache for credentials matching the request URL. The lookup walks a trie of URL path segments for the request's origin.

The pull request description states the bug precisely: when uv caches different credentials for /team and /team/private/simple on the same origin, the parent entry shadows the child, even for an exact match on /team/private/simple. The lookup returned the first entry it met while walking the path, which is the shortest. The fix keeps track of the deepest entry as the walk continues, so the most specific prefix wins.

RFC 7617, which defines HTTP Basic authentication, says in section 2.2 that a client may assume that all paths at or deeper than the last symbolic element of a request path are in the same protection space. It does not say which credential to use when two protection spaces nest. The pull request notes this and chooses the longest match as the more intuitive answer.

Measured with a local index

The local probe checked the behaviour with both releases, downloaded from the GitHub release assets with their published SHA-256 checksums verified. A local Python HTTP server on 127.0.0.1 served a PEP 503 simple index and required Basic authentication: requests under /team/private/ needed the user private, everything else under /team/ needed the user team. Both passwords were synthetic and created at run time. A single package, shelfnote, was available only from the private index. The server recorded which user each request carried.

The command was the same for both versions, with configuration files, environment overrides, the keyring and netrc disabled:

uv pip compile req.in --no-cache --python-version 3.12 \
  --index-url "http://private:<child-pw>@127.0.0.1:<port>/team/private/simple" \
  --extra-index-url "http://team:<parent-pw>@127.0.0.1:<port>/team"

The probe ran twice: once with the wheel link pointing inside the index, at /team/private/simple/shelfnote/, and once pointing at a separate files path, /team/private/files/, which is how many repository servers lay out downloads.

RequestCredential neededuv 0.13.10 sentuv 0.13.11 sent
/team/shelfnote/ (project page on the extra index)teamteam, 200team, 200
/team/private/simple/shelfnote/ (project page)privateprivate, 200private, 200
Wheel under /team/private/simple/shelfnote/privateteam, 401private, 200
Wheel under /team/private/files/privateteam, 401private, 200

uv 0.13.10 exited with status 2 and the message HTTP status client error (401 Unauthorized) for the wheel URL in both layouts. uv 0.13.11 resolved shelfnote==0.1.0 and exited with 0 in both.

Two details in the table explain more than the release note says. First, the project page under the private index was fetched with the right credential even in 0.13.10. The failure appeared on the next request, the wheel download, after credentials had been cached for both prefixes. Second, the files path outside /simple also received the private credential in 0.13.11. With trace logging, uv listed three cached credential URLs: /team/private/simple, /team, and /team/private. The last one is the index root: uv caches credentials for an index both at its URL and at that URL with the final simple segment removed, so downloads served from a sibling path still match. The test in the pull request describes a path that diverges before the child entry falling back to the parent; in this layout the cached index root was the longer match.

Who is affected

You are affected if all of these hold:

  • Two or more indexes, or an index and a separate download location, are on the same scheme, host and port.
  • One index path is a prefix of the other.
  • They use different credentials.
  • You run uv 0.13.10 or earlier.

Typical cases are a repository manager that exposes group and member repositories under one host, or a team that put a restricted repository below a shared one. A single private index, or several indexes on different hosts, are not affected.

The local fixture produced an authentication error and showed the wrong user at a path on the same origin. That does not establish that every real deployment has one trust boundary: a reverse proxy can route different paths to different operators. Treat the incorrect credential selection as a scoping problem as well as an availability problem. Log a non-secret account identifier, never the Authorization header or password.

What to do

  1. Upgrade uv to 0.13.11 or later on developer machines and in CI. If you pin uv in CI, as you should, change the pin and the checksum together.
  2. Remove workarounds. Teams hit by this often gave both indexes the same credential, or moved one index to another host name. Once uv is upgraded, scoped credentials work as intended and the shared credential can be retired.
  3. Keep credentials out of command lines and files that are committed. Pass them through environment variables or a keyring, as described in uv's authentication documentation. The probe above uses URLs with embedded credentials only because it runs against a local server with synthetic passwords.
  4. Prefer separate credentials per index, scoped to the narrowest path that works, now that the client honours them.

A quick check that does not depend on uv internals is to run your install with trace logging and look for the request that fails. If a 401 appears on a URL under the more specific index and the user in your server log is the broader one, you have this bug.

def expected_credential(url_path: str, scopes: dict[str, str]) -> str | None:
    """Pick the credential whose path prefix is the longest match for url_path."""
    best, best_len = None, -1
    for prefix, user in scopes.items():
        p = prefix.rstrip("/")
        if (url_path == p or url_path.startswith(p + "/")) and len(p) > best_len:
            best, best_len = user, len(p)
    return best

scopes = {"/team": "team", "/team/private": "private", "/team/private/simple": "private"}
assert expected_credential("/team/private/files/shelfnote-0.1.0-py3-none-any.whl", scopes) == "private"
assert expected_credential("/team/shelfnote/", scopes) == "team"

The companion example uses this function to state the expected user for every request and compares it with what the local server saw.

Failure modes after upgrading

  • Mixed uv versions. A developer or CI runner still on 0.13.10 or earlier keeps sending the wrong credential, whatever version produced the lock file. Pin the version in CI and in the developer setup documentation.
  • Other tools. pip and other clients have their own credential selection. A fix in uv does not change what they send. Test each client you support.
  • Servers that redirect. If the index redirects downloads to another host or path, the credential lookup happens against the redirected URL, and uv's rules for credentials on redirects apply.

How to verify it

The companion example uv_credential_prefix_probe downloads uv 0.13.10 and 0.13.11 with checksums pinned, starts the local server, runs the command above against both download layouts and asserts the exact user sent on every request and the exit status of each run. It needs no network access beyond the two downloads and no real credentials.

Primary references and authorship

Sources checked 2026-12-02. Original explanation and synthetic examples by Sandeep Belgavi. Companion code: Sandeep-BA/agent-decision-lab/examples/python/uv_credential_prefix_probe. Views are my own and do not represent any employer, past or present.