Skip to main content
Vulnerability Database/CVE-2026-81856

CVE-2026-81856: Hex Package Manager XSS Vulnerability

CVE-2026-81856 is a terminal control sequence injection flaw in hexpm hex that lets attackers inject ANSI escape codes and Unicode overrides to forge displayed content. This article covers technical details, affected versions, impact, and mitigation strategies.

Published:

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

CVE-2026-81856 Overview

CVE-2026-81856 is a terminal control sequence injection vulnerability in hex, the package manager for the Erlang ecosystem maintained by hexpm. The flaw allows a malicious package publisher or a hostile repository server to inject ANSI escape sequences and Unicode bidirectional overrides into the output of Mix tasks. Hex prints repository-supplied strings directly to the terminal through Hex.Shell.info/1 and Hex.Shell.error/1 without neutralizing control characters. Attackers can forge displayed URLs, hide output, write to the user's clipboard via OSC 52, or suggest malicious commands. The vulnerability affects hex versions from 0.0.1 before 2.5.2 and is tracked under [CWE-150: Improper Neutralization of Escape, Meta, or Control Sequences].

Critical Impact

An attacker only needs to publish a package to trigger the injection. No authentication or privileged position is required against the victim developer running Mix tasks.

Affected Products

  • hexpm hex versions 0.0.1 through 2.5.1
  • Mix tasks including mix hex.info, mix hex.package search, mix hex.search, mix hex.user, and mix hex.policy
  • Any Elixir or Erlang development environment that consumes packages from a Hex repository

Discovery Timeline

  • 2026-10-12 - CVE-2026-81856 published to NVD
  • 2026-10-16 - Last updated in NVD database

Technical Details for CVE-2026-81856

Vulnerability Analysis

The vulnerability stems from Hex writing untrusted repository content directly to the user's terminal. Functions Hex.Shell.info/1 and Hex.Shell.error/1 forward bytes to standard output without sanitizing ANSI escape sequences, carriage returns, or Unicode bidirectional override characters. Affected sinks span package metadata and configuration snippets in mix hex.info, search results in mix hex.package search and mix hex.search, owner and organization listings, publish and sponsor URLs, the authenticated username in mix hex.user, policy identities in mix hex.policy, and API error bodies rendered by Hex.Utils.print_error_result/1.

An attacker publishing a package with crafted metadata can move the cursor, erase lines, hide genuine output, or re-render fake URLs and shell commands. Operating System Command (OSC) 52 sequences can silently write attacker-controlled text to the developer's clipboard, which may later be pasted into a shell. Bidirectional overrides can reorder characters so a displayed command differs from the executed command.

Root Cause

Hex trusts that strings returned from the package repository and documentation search service are safe for terminal display. No escape, meta, or control character filtering is applied before writing to the TTY. The remediation introduced a shared Hex.Utils.escape_terminal/1 helper and applies it at every output sink that renders server-supplied data.

Attack Vector

Exploitation requires network delivery via the Hex repository and user interaction (running a Mix command). A publisher embeds control sequences in a field such as the package description, sponsor URL, owner name, or policy identity. When a developer runs an affected Mix task, the sequences execute against the terminal emulator, enabling spoofed output or clipboard writes.

text
# Patch snippet from lib/hex/cooldown.ex - escape untrusted content
        [
          "  ",
          :bright,
-         pkg,
+         Hex.Utils.escape_terminal(pkg),
          :reset,
          " ",
          :yellow,
text
# Patch snippet from lib/hex/policy/diagnostics.ex
    ([header, cooldown_line] ++ hidden_lines)
    |> Enum.reject(&is_nil/1)
    |> Enum.join("\n")
+   |> Hex.Utils.escape_terminal()
  end

Source: hexpm/hex commit dd3305ddf0032f6d0b468fd40dbbc3072bfcb8b8

Detection Methods for CVE-2026-81856

Indicators of Compromise

  • Mix task output containing raw escape bytes (0x1B, \e[, \e]52;) when captured to log files or CI artifacts.
  • Unexpected clipboard contents on developer workstations immediately after running Hex commands.
  • Package metadata fields in Hex that contain non-printable or bidirectional control characters (U+202E, U+2066-U+2069).
  • Discrepancies between the URL shown in a terminal and the URL stored in registry responses.

Detection Strategies

  • Scan CI/CD logs and developer shell history for ANSI control sequences originating from mix hex.* command output.
  • Inspect downloaded Hex registry responses for control characters before rendering, using a byte-level validator.
  • Compare installed hex version against 2.5.2 across build agents and developer endpoints.

Monitoring Recommendations

  • Monitor outbound requests from developer workstations to repositories that mirror Hex content and log the raw payloads for offline inspection.
  • Alert on process executions where mix is the parent of clipboard-interacting utilities or unexpected shells.
  • Track Hex package publishes consumed by internal projects and flag new packages whose metadata contains non-ASCII control bytes.

How to Mitigate CVE-2026-81856

Immediate Actions Required

  • Upgrade hex to version 2.5.2 or later on every developer workstation, build server, and container image.
  • Audit recent Mix task output and clipboard activity on systems that ran mix hex.info, mix hex.search, or related tasks against untrusted packages.
  • Review any shell commands recently pasted from the clipboard on affected developer machines for signs of injected payloads.

Patch Information

The fix is delivered in hex2.5.2. The maintainers introduced a Hex.Utils.escape_terminal/1 helper that neutralizes control bytes before writing repository-supplied strings to the shell. See GitHub Security Advisory GHSA-fpmj-3cxg-p766 and the CNA advisory for CVE-2026-81856 for full details, and the remediation commit dd3305ddf0032f6d0b468fd40dbbc3072bfcb8b8.

Workarounds

  • Pipe Mix task output through a filter that strips escape sequences, for example mix hex.info <pkg> | cat -v, until upgrading is possible.
  • Disable OSC 52 clipboard writes in the terminal emulator configuration where supported.
  • Restrict dependency sources to a vetted internal Hex mirror and reject packages whose metadata contains control characters.
bash
# Upgrade hex to the patched release
mix local.hex 2.5.2 --force

# Verify the installed version
mix hex.info | head -n 2

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.