Summary
OpenWrt's odhcpd service previously wrote unescaped hostnames into a lease file that LuCI rendered as live HTML in the web-based admin interface.
An attacker who can supply a crafted DHCPv6 hostname can inject malicious script content, leading to stored cross-site scripting when an administrator views the Active DHCPv6 Leases page.
Affected context
The vulnerability occurs in OpenWrt deployments using odhcpd together with the LuCI web interface for administration.
When DHCPv6 clients provide fully qualified domain names (FQDNs), odhcpd writes these values into /tmp/odhcpd.leases without escaping.
LuCI's RPC layer and JavaScript views then read this lease file and insert the hostname strings directly into the DOM as HTML on the Active DHCPv6 Leases status page.
Environments where untrusted or semi-trusted devices can obtain DHCP leases are particularly exposed to this issue.
Exploit preconditions
- Attack surface: OpenWrt LuCI web administration interface (Active DHCPv6 Leases page).
- Required access: Ability to connect a device or virtual client to the affected network segment and obtain a DHCPv6 lease, while controlling the client's hostname/FQDN option.
- Trigger point: An authenticated administrator (or other LuCI user with access) opens or refreshes the Active DHCPv6 Leases page, causing LuCI to read
/tmp/odhcpd.leasesand render the injected content. - Why exploitation is possible: Hostname values are written to the lease file without escaping or validation (CWE-117 / CWE-150), and later interpreted as HTML/JavaScript in the browser without proper output encoding (CWE-79), enabling script execution in the admin's session.
Why this happens
The root cause is a combination of improper output encoding and unsafe handling of log/state data across trust boundaries.
odhcpd's statefiles_write_state6() and statefiles_write_state4() functions accept DHCP client FQDN values and write them directly into a state file without escaping special characters or line breaks (CWE-117: Improper Output Neutralization for Logs; CWE-150: Improper Neutralization of Escape, Meta, or Control Sequences).
LuCI subsequently treats the file contents as trusted data and inserts them into the DOM using functions like dom.append without HTML encoding (CWE-79: Improper Neutralization of Input During Web Page Generation), allowing attacker-controlled content to become executable script in the admin's browser.
Potential impact
- Theft of administrator session data or browser-accessible tokens via injected JavaScript.
- Unauthorized actions in the LuCI interface performed on behalf of the administrator (e.g., configuration changes, adding SSH keys, modifying firewall rules).
- Injection of misleading or spoofed UI content, potentially tricking administrators into dangerous actions.
- Pivoting to other internal resources reachable from the administrator's browser context (e.g., CSRF-style attacks against adjacent services).
- Persistent compromise of the router's management plane as long as the malicious lease entry remains active.
General mitigation guidance
Effective mitigation focuses on strict separation between data storage formats and rendered HTML, along with treating all client-supplied identifiers as untrusted:
- Apply context-appropriate output encoding for any data rendered into HTML, ensuring hostnames and other lease fields are HTML-escaped before DOM insertion.
- Normalize and validate DHCP client identifiers, enforcing a conservative character set and rejecting or sanitizing control characters, newlines, and markup-like sequences.
- Treat state and lease files as untrusted input surfaces; when reading them for web presentation, re-validate their contents rather than trusting them as internal-only data.
- Limit administrative exposure by restricting LuCI access to dedicated management networks and accounts with least-privilege permissions.
- Prefer UI components and templating helpers that encode by default, reducing the likelihood of raw string insertion into the DOM.
How teams detect issues like this
Detection commonly involves a mix of code-level analysis and runtime inspection:
- Use static analysis and linters to flag direct insertion of untrusted data into the DOM (e.g.,
innerHTML,dom.appendwith raw strings) without encoding. - Review paths where network-originated data (such as DHCP options) flows into state or log files, and then into web views, checking for missing validation or escaping at each hop.
- Implement security-focused code review checklists requiring explicit output encoding for any values stored in system files and later displayed in the UI.
- Employ dynamic testing and fuzzing of DHCP client fields (especially hostnames and FQDNs) to detect script injection in rendered admin pages.
- Consider using automated SAST/DAST tools that recognize XSS patterns and unescaped log-to-UI data flows in web administration interfaces.

