Summary
A critical OS command injection vulnerability in wg-easy allows an authorized user to inject additional WireGuard PostUp directives through a client name.
When the crafted name is written to the WireGuard configuration, wg-quick may execute the injected commands with root privileges on the host.
Affected context
The vulnerability occurs in wg-easy deployments where users with the clients.create permission can create WireGuard clients and supply a client name that is incorporated into generated configuration files. Risk exists when newline characters and directive content are preserved rather than treated strictly as data before the configuration is processed by wg-quick.
Exploit preconditions
- Attack surface: The client-creation functionality and generated WireGuard configuration
- Required access: An authenticated account with the
clients.createpermission - Trigger point: Creation or activation of a client whose name is written into a WireGuard configuration
- Why exploitation is possible: Newline characters are not neutralized, allowing client-controlled text to become additional
PostUpdirectives executed bywg-quick
Why this happens
The underlying bug is improper neutralization of user-controlled input used in an operating-system command configuration context. A client name is treated as ordinary text but is inserted into a line-oriented WireGuard configuration without enforcing field boundaries or rejecting control characters.
This maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command, because attacker-controlled data can alter command-bearing directives that are later interpreted with root privileges.
Potential impact
- An attacker may execute arbitrary operating-system commands as root
- The host running wg-easy could be fully compromised
- Attackers could access, modify, or delete local data
- Network credentials and WireGuard private material could be exposed
- The compromised host could be used for lateral movement or service disruption
General mitigation guidance
Mitigation generally focuses on ensuring that user-controlled client metadata cannot become configuration syntax or executable command content.
Common defensive patterns include:
- Enforcing strict allowlists for client-name characters and rejecting control characters
- Encoding or safely serializing values according to the WireGuard configuration grammar
- Keeping command-bearing directives separate from user-provided metadata
- Avoiding shell-interpreted command construction where structured APIs or fixed trusted commands are available
- Applying least privilege to the service and limiting the privileges of processes that activate network configurations
- Restricting which roles can create clients and reviewing permission assignments regularly
- Treating generated configuration files as security-sensitive artifacts with controlled ownership and write access
How teams detect issues like this
Detection approaches can include:
- Static analysis for string interpolation or concatenation of user input into shell commands and line-oriented configuration files
- Code review checks for missing validation of newline, carriage-return, shell metacharacter, and directive-specific input
- Tests that submit boundary and control-character values to all client-name creation paths
- Monitoring generated WireGuard configurations for unexpected additional directives or command-bearing fields
- Auditing client-creation events and correlating them with unusual privilege-level process execution
- Policy enforcement requiring allowlisted identifiers and security review for code that generates privileged configuration

