Repository navigation
Device Details: <select> dropdowns (devGroup, devLocation, devSite, etc.) fail to select current value when it contains HTML special characters like '&' #1853
Description
What installation are you running?
Production (netalertx) 📦
Is there an existing issue for this?
- I have searched the existing open and closed issues and I checked the docs https://docs.netalertx.com/
The issue occurs in the following browsers. Select at least 2.
- Firefox
- Chrome
- Edge
- Safari (unsupported) - PRs welcome
- N/A - This is an issue with the backend
Current Behavior
In deviceDetails.php (deviceDetailsEdit.php), when a <select> field such as devGroup, devLocation, or devSite has a stored value in the Devices table that contains an HTML special character (most commonly &, e.g. devGroup = "Server & NAS" or "Smart Home & Media"), the dropdown in the Device Details tab fails to mark the matching <option> as selected and instead falls back to the first option (❌None / "").
Furthermore, if the user subsequently edits any other field on that device and clicks Save, setDeviceData() reads $("#NEWDEV_devGroup").val() (which is "") and silently overwrites the device's devGroup with "" in the database.
Root Cause:
- In
front/deviceDetailsEdit.php(line 336),fieldDatais HTML-entity-encoded before being passed intogenerateFormHtml():For// XSS prevention - encode special characters for string fields, but not for arrays (like children dynamic) fieldData = encodeSpecialChars(fieldData);
"Server & NAS",fieldDatabecomes"Server & NAS", which is passed asoverrideValue->inVal->val->valuesArray = ["Server & NAS"]. - In
front/js/db_methods.js(renderList) andfront/js/settings_utils.js(generateOptions, lines 1014–1016), the available options forNEWDEV_devGroupare fetched via/dbquery/read(SELECT DISTINCT ... devGroup as id, devGroup as name FROM ...), which returns raw unencoded strings from SQLite (item.id = "Server & NAS"). generateOptions()then checks:Becauselet selected = options.length !== 0 && valuesArray.includes(item.id) ? 'selected' : ''; optionsHtml += `<option class="${cssClass}" value="${encodeSpecialChars(item.id)}" ${selected}>${encodeSpecialChars(labelName)}</option>`;
valuesArraycontains"Server & NAS"(already encoded indeviceDetailsEdit.php:336) whileitem.idis"Server & NAS"(unencoded),valuesArray.includes(item.id)evaluates tofalse.
Note that generateFormHtml() / generateOptions() already encodes item.id and labelName via encodeSpecialChars() when rendering <option>, or for <input> fields in generateFormHtml() where val is interpolated. Alternatively, generateOptions() can compare valuesArray.includes(item.id) || valuesArray.includes(encodeSpecialChars(item.id)).
Expected Behavior
<select> dropdowns in deviceDetailsEdit.php (devGroup, devLocation, devSite, devType, etc.) should properly pre-select the device's current value even when the value contains & (e.g. "Server & NAS"), and saving the device should not wipe the field to "".
Steps To Reproduce
- Assign a device a
devGroupcontaining&, e.g.Server & NAS(via Multi-Edit, Workflows, or Device Details). - Reload
deviceDetails.php?mac=<mac>. - Observe that the Group (
NEWDEV_devGroup) dropdown displays❌Noneinstead ofServer & NAS, even thoughServer & NASis present in the dropdown options list and in the database (Devices.devGroup). - Click Save on the device ->
devGroupis overwritten with""(❌None).
Relevant app.conf settings
# Default NEWDEV_devGroup SQL options from server/plugins/newdev_template/config.json
NEWDEV_devGroup=""docker-compose.yml
services:
netalertx:
image: ghcr.io/netalertx/netalertx:26.10.0
network_mode: host
cap_drop:
- ALL
cap_add:
- NET_ADMIN
- NET_RAW
- NET_BIND_SERVICEDebug or Trace enabled
- I have read and followed the steps in the wiki link above and provided the required debug logs and the log section covers the time when the issue occurs.
Relevant app.log section
N/A (Pure frontend JavaScript issue in front/deviceDetailsEdit.php:336 and front/js/settings_utils.js:1014; backend /dbquery/read returns {"results":[{"id":"","name":"❌None"},{"id":"Server & NAS","name":"Server & NAS"}], "success":true})
Docker Logs
N/A (Frontend JS rendering issue in deviceDetailsEdit.php / settings_utils.js)
Activity