Summary
Pi-hole's FTL engine (FTLDNS) from versions 6.0 to before 6.6 contains a command injection vulnerability in the dns.cnameRecords configuration parameter.
An authenticated attacker who can write crafted CNAME configuration data can inject arbitrary dnsmasq directives via newline characters and ultimately execute commands on the underlying system.
Affected context
This vulnerability occurs in Pi-hole deployments using FTLDNS (pihole-FTL) versions 6.0 through 6.5.x, where dns.cnameRecords is configurable via the interactive API or related management interfaces.
It becomes risky when attacker-controlled or weakly validated configuration values are written into dnsmasq configuration contexts, and those values are later interpreted as part of the DNS server configuration.
The issue is most relevant in environments where multiple users or automated systems can interact with Pi-hole's API or where configuration updates are exposed beyond a single trusted administrator.
Exploit preconditions
- Attack surface: Pi-hole FTL interactive API or any interface that updates
dns.cnameRecords. - Required access: Authenticated access to modify Pi-hole DNS configuration, including CNAME records or equivalent configuration structures.
- Trigger point: Processing and persistence of
dns.cnameRecordssuch that newline characters and attacker-supplied content are injected into dnsmasq configuration; subsequent reload or use of this configuration by the FTL engine. - Why exploitation is possible: User-controlled configuration data is concatenated into dnsmasq configuration without proper sanitization or normalization, allowing newline characters to break out of the intended parameter and inject arbitrary configuration directives that can be leveraged to reach OS command execution.
Why this happens
The core issue is improper handling of special characters and control sequences when mapping user-provided configuration values into dnsmasq configuration files or in-memory directives.
Instead of strictly validating or sanitizing dns.cnameRecords content, the implementation allows newline characters to be embedded, which breaks the configuration structure and enables injection of additional dnsmasq options.
This behavior maps to CWE-78 (OS Command Injection) because the injected configuration ultimately influences how commands or system-level actions are invoked, and to CWE-93 (Improper Neutralization of CRLF Sequences) due to the failure to neutralize newline (CR/LF) characters in a context where line-based configuration is parsed as executable directives.
Conceptually, it is an injection bug where untrusted input crosses a trust boundary into a configuration channel that controls downstream command execution.
Potential impact
- Remote execution of arbitrary commands with the privileges of the Pi-hole FTL/dnsmasq process.
- Complete compromise of the host running Pi-hole if the service has high or privileged access.
- Modification or redirection of DNS responses to facilitate phishing, malware distribution, or traffic interception.
- Establishment of persistence mechanisms or lateral movement within the local network environment.
- Disruption of DNS service, leading to denial-of-service for dependent clients.
General mitigation guidance
Effective mitigation centers on hardening how configuration data is accepted, stored, and rendered into dnsmasq or other system-level components.
Recommended patterns include:
- Strict input validation: Treat CNAME configuration as data only; enforce tight character whitelists (e.g., domain-name character sets), length limits, and structural validation before accepting or persisting values.
- Normalization and encoding: Strip or reject control characters such as
\n,\r, and other delimiters in any user-supplied input that will be mapped into line-based configuration; normalize data before concatenation. - Context-aware construction: Build configuration using structured APIs or templates that separate data from control, rather than string concatenation; avoid directly embedding raw user input into configuration files.
- Least privilege execution: Run Pi-hole and associated DNS components with the minimum required OS privileges and restricted filesystem and network permissions to limit the blast radius of any compromise.
- Configuration access controls: Restrict who and what can modify dns-related configuration via the API or UI, ensuring strong authentication, authorization, and logging for administrative actions.
- Defense in depth: Combine network segmentation, OS-level sandboxing (e.g., chroot, containers, namespaces), and application-level rate limiting to reduce the overall exploitation surface.
How teams detect issues like this
To identify and monitor for this vulnerability class, organizations can adopt a combination of code-level and operational detection techniques:
- Static analysis patterns:
- Flag concatenation of user-controllable strings into configuration lines destined for dnsmasq or other interpreters.
- Detect lack of sanitization or filtering for newline (
\n,\r\n) and other control characters in API handlers dealing with DNS record parameters. - Highlight any code paths where configuration strings are written directly to configuration files without encoding or structural validation.
- Code review signals:
- Presence of APIs that allow arbitrary CNAME or DNS record values without clear validation logic.
- Configuration-writing functions that accept raw input and construct line-based config using string interpolation or direct writes.
- Missing or minimal boundary checks around domain-related fields, especially when those are used outside of pure DNS response generation.
- Runtime and log-based detection:
- Monitor dnsmasq or Pi-hole logs for unusual or malformed configuration entries or errors after configuration changes.
- Alert on unexpected commands, processes, or child processes spawned by the DNS service account.
- Implement audit logging and anomaly detection around administrative API calls modifying DNS configuration.
Automated security scanning tools, including SAST and policy-as-code engines, can help enforce these patterns across codebases and configuration repositories.

