Summary
Pi-hole's FTL engine (FTLDNS) versions 6.0 to before 6.6 contain a remote code execution vulnerability in the dns.upstreams configuration parameter that backs the interactive API and web interface statistics.
An authenticated attacker who can modify upstream DNS settings can inject arbitrary dnsmasq configuration directives via newline characters, which can be abused to execute commands on the underlying system.
Affected context
The vulnerability exists in Pi-hole deployments using FTL (FTLDNS) versions 6.0 to before 6.6 where the upstream DNS servers (dns.upstreams) can be configured through the interactive API or linked administrative interfaces.
It manifests in environments where user-controlled configuration values are translated into dnsmasq configuration without robust sanitization of special characters such as newlines.
This typically affects Pi-hole instances exposed to authenticated users (local or remote) who have permission to manage DNS settings.
Exploit preconditions
- Attack surface: Pi-hole FTL API / configuration interface that sets the
dns.upstreamsvalue. - Required access: Valid authenticated access with privileges to modify upstream DNS configuration (e.g., admin web access, API token).
- Trigger point: Saving or updating the
dns.upstreamsparameter so that FTL generates or passes modified dnsmasq configuration and reloads/applies it. - Why exploitation is possible: The application fails to properly sanitize or constrain the
dns.upstreamsinput, allowing newline characters and additional dnsmasq configuration directives to be injected. Those injected directives can be crafted to influence how commands or scripts are invoked, resulting in command execution on the host.
Why this happens
This issue stems from treating a partially trusted configuration parameter (dns.upstreams) as if it were safe to interpolate directly into dnsmasq configuration without strict validation or encoding.
By allowing newline characters and not enforcing a strict schema (e.g., only valid IP addresses or hostnames), the software effectively permits arbitrary configuration lines to be appended or inserted.
This maps primarily to CWE-78: Improper Neutralization of Special Elements used in an OS Command, because user-controllable data affects command-related behavior, and secondarily to CWE-93: Improper Neutralization of CRLF Sequences, since line breaks are used to escape the intended configuration context.
Abstractly, the insecure pattern is: user-controlled text is concatenated into a configuration or command boundary without filtering metacharacters that alter structure and semantics.
Potential impact
- Remote execution of arbitrary commands with the privileges of the Pi-hole FTL/dnsmasq process.
- Complete compromise of the Pi-hole host system, including potential pivoting to adjacent services.
- Manipulation of DNS behavior to redirect, block, or spoof traffic.
- Installation of persistent malware or backdoors on the system.
- Exfiltration or tampering with DNS logs and configuration data.
General mitigation guidance
Effective mitigation focuses on constraining and validating configuration inputs and reducing the impact of any misconfiguration:
- Strict input validation and typing: Treat
dns.upstreamsas a structured value (e.g., an array of IP addresses/hostnames) and validate against a whitelist of allowed patterns, disallowing control characters, whitespace beyond separators, and any non-address tokens. - Context-aware encoding: When rendering user-supplied data into configuration files or command lines, ensure it is escaped or encoded so that metacharacters cannot break out of the intended field.
- Configuration schema enforcement: Use a schema or typed configuration model that only allows well-formed upstream entries, rejecting values that do not conform.
- Least-privilege execution: Run the DNS/FTL components with minimal privileges and limited filesystem/OS access to reduce the blast radius of any command execution.
- Separation of concerns: Avoid direct, implicit translation of user-facing configuration into low-level dnsmasq directives; instead, map high-level options to a constrained set of generated directives.
- Defense-in-depth controls: Restrict administrative access to the Pi-hole UI/API, use strong authentication, and limit network exposure of the management interfaces.
How teams detect issues like this
Detection can combine code-level analysis, configuration review, and runtime monitoring:
- Static analysis: Scan for paths where user or API input is written into configuration files or used to influence command execution without robust validation or encoding. Patterns include concatenation of raw strings into dnsmasq config templates or shell command arguments.
- Code review signals: Look for:
- Configuration-building logic that interpolates user data directly into text templates.
- Lack of validation on upstream DNS values (e.g., accepting arbitrary strings instead of validated IPs/hostnames).
- Handling of newline or control characters in configuration-related fields.
- Policy enforcement: Introduce coding standards requiring:
- Structured parsing and validation for configuration parameters.
- Prohibiting shell invocation or command construction using untrusted input even indirectly via configuration.
- Runtime monitoring: Track abnormal command executions or dnsmasq invocations triggered after configuration changes, and inspect configuration files for unexpected extra directives.
- Automated tooling: Integrate SAST/linters and infrastructure-as-code scanners into CI/CD pipelines to flag command-injection-prone patterns and unsafe configuration template handling.

