Mercurial HTTPS push continues after server password change without cache clear
0 reputation · 02 Mar 2021, 23:01 UTC
0 reputation · 02 Mar 2021, 23:01 UTC
Determine whether Mercurial automatically invalidates cached HTTPS credentials when the server‑side password is changed, or if manual cache clearing or process restart is required for the change to take effect.
Mercurial stores HTTPS credentials in the operating system keyring or .hgrc and does not query the store for expiration until the cache entry is explicitly cleared or the Mercurial process restarts, leaving a window where outdated credentials may still be used.
Does Mercurial offer a setting to disable credential caching for HTTPS? Is there a way to force Mercurial to re‑query the keyring before each operation? Should administrators rely on external key‑rotation policies to enforce credential expiration?
Mercurial does not proactively invalidate cached HTTPS credentials when the server-side password changes. It has no way to know the password changed; it only reacts when the server rejects a request. The typical flow is: the client sends the cached credential, the server answers 401 Unauthorized with an authentication challenge, and only then does Mercurial discard the failed credential and re-query the configured source (keyring, credential helper, or interactive prompt). Until a 401 occurs, the old credential is simply replayed.
What is well established: HTTP authentication is stateless and challenge-driven. Mercurial sends credentials per request and treats a 401 as the signal that the credential is wrong. There is no polling of the server for password validity and no built-in TTL on cached credentials.
What is likely in your case, but worth verifying: if pushes keep succeeding after the password change, the server is probably still accepting the old credential — for example because the change hasn't propagated (replicated LDAP/AD with sync lag), the server caches authentication results itself, or the account has multiple valid credentials. Mercurial cannot succeed with a credential the server truly rejects. So if the push works, the server authorized it; the caching question is on the server side, not the client.
Conversely, if you expect the push to fail and it doesn't prompt for a new password, check whether the server returns a proper 401. Some servers or proxies return 403 or a custom error page instead, which Mercurial does not treat as "wrong password," so no re-query happens.
[auth] entries in .hgrc. To avoid persistent caching, don't configure a keyring helper and don't put passwords in .hgrc; Mercurial will then prompt per session.hg command is a fresh process, in-memory caching is not the issue; the persistent store (keyring or .hgrc) is. The practical lever is removing or updating the stored entry.hg push --debug 2>&1 | grep -i -E "http|401|auth" Look for whether the request is accepted outright or challenged.[auth] section of .hgrc. No Mercurial restart is needed beyond starting a new command.Exact behavior depends on your Mercurial version, the credential helper in use, and the server/proxy stack; the above reflects long-standing behavior but should be verified against your installation. One diagnostic detail would sharpen the recommendation: the HTTP status code the server returns for a request with the old password — that determines whether this is a client caching issue or a server acceptance issue.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.