The commit looked clean. The diff was tight. But buried in the routine was an opening—a flaw that turned Mercurial into a weapon.
Mercurial privilege escalation happens when the version control system exposes paths or commands that let a user gain more privileges than intended. It’s not a code bug in your repository—it’s a security failure in how Mercurial processes input, manages permissions, or integrates with external tools. This can unlock unauthorized file access, OS command execution, or control over repositories you’re supposed to protect.
Most escalation risks in Mercurial surface through poorly enforced access controls in hooks, extensions, or repository configurations. Common triggers include:
- Maliciously crafted
.hgdirectories bypassing checks. - Hooks running with elevated privileges without sanitizing environment variables.
- Extension code executing shell commands directly from repository data.
- Misconfigured server or SSH command restrictions allowing raw Mercurial commands.
Once exploited, these flaws give attackers write access to protected branches, inject rogue commits, or even compromise the host system. From there, privilege escalation isn’t just about a single repo—it can cascade into full infrastructure compromise.