Summary
luci-app-upnp contains a stored cross-site scripting flaw where malicious JavaScript can be injected via UPnP AddPortMapping metadata and later executed in an administrator's browser.
When an attacker on the LAN submits crafted HTML in the NewPortMappingDescription field, miniupnpd persists it and luci-app-upnp renders it without output encoding on the UPnP or Status pages, allowing unauthorized script execution in the router's management context.
Affected context
This vulnerability appears in router or gateway deployments that:
- Expose the luci-app-upnp web interface for managing UPnP port mappings
- Run miniupnpd or a compatible UPnP IGD daemon that stores port mapping descriptions
- Allow untrusted or semi-trusted LAN clients to send UPnP AddPortMapping SOAP requests
The issue manifests when luci-app-upnp displays stored port mapping descriptions on UPnP or Status pages without applying proper HTML/JavaScript output encoding in the administrator's browser.
Exploit preconditions
- Attack surface: Internal network (LAN-side) via UPnP IGD AddPortMapping requests and the router's web UI.
- Required access: Ability to send UPnP SOAP requests from a LAN client (no web UI login required) and the presence of an administrator who later opens the luci-app-upnp or Status pages.
- Trigger point: Display of the malicious NewPortMappingDescription field in the browser when the admin visits the affected pages.
- Why exploitation is possible: The application treats stored port mapping descriptions as trusted content, rendering them directly into HTML without contextual output encoding or sanitization, enabling attacker-controlled script execution in the admin's session.
Why this happens
The root cause is improper output handling of untrusted data that originates from UPnP AddPortMapping requests and is later rendered in the web UI.
luci-app-upnp reads the NewPortMappingDescription field, previously stored by miniupnpd, and injects it into HTML pages without escaping special characters or stripping script-capable constructs.
This matches CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-Site Scripting), where data accepted from an external source is incorporated into a web page without context-aware encoding, allowing execution of arbitrary JavaScript in the victim's browser.
Potential impact
- Execution of arbitrary JavaScript in the administrator's browser when viewing UPnP or Status pages
- Theft or misuse of administrative session tokens or CSRF tokens
- Unauthorized configuration changes on the router via script-driven UI actions
- Installation or modification of firewall and port forwarding rules under the admin's authority
- Use of the router management session for further internal network reconnaissance or pivoting
General mitigation guidance
Effective mitigation centers on treating all UPnP-sourced metadata as untrusted and ensuring it cannot be rendered as active content.
Common defensive patterns include:
- Applying strict, context-aware output encoding for any user- or device-supplied text before inserting it into HTML templates (e.g., escaping
<,>,",', and&in text and attribute contexts). - Constraining allowed description fields to a safe character set and length, rejecting or normalizing unexpected markup-like input.
- Isolating dynamic content using safe templating engines that encode output by default, instead of building HTML via string concatenation.
- Applying least-privilege principles in the web interface so that actions triggered from a single page have limited scope where practical.
- Optionally segregating or disabling UPnP features in environments where untrusted LAN clients exist, to reduce exposure of the management plane to arbitrary metadata.
How teams detect issues like this
Organizations can detect and monitor for this class of issue through:
- Static analysis rules or linters that flag direct insertion of external data into HTML responses without passing through encoding or templating helpers.
- Code review checklists that explicitly call out XSS risks when handling UPnP fields, query parameters, or configuration descriptions displayed in the UI.
- Security testing that exercises UPnP AddPortMapping requests with benign HTML/JavaScript markers and verifies whether they appear unescaped in rendered pages.
- Periodic content inspection of stored port mapping descriptions for suspicious markup patterns indicative of attempted XSS payloads.

