Device Details: <select> dropdowns (devGroup, devLocation, devSite, etc.) fail to select current value when it contains HTML special characters like '&'
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 78/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- javascript, python, sqlite
Direzione di ricerca
Inizia in front/deviceDetailsEdit.php, nella parte relativa alla codifica di fieldData, e segui come overrideValue arriva a generateOptions() in front/js/settings_utils.js; l’issue indica anche front/js/db_methods.js come origine dei dati delle opzioni. Controlla come vengono confrontati i valori codificati con i valori grezzi del database, poi riproduci il problema con un gruppo come «Server \u0026 NAS». Il lavoro è completato quando l’opzione corrente è selezionata e il salvataggio di un altro campo conserva il gruppo.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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_SERVICE
Debug 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)
- Lingua principale
- Python
- Stelle
- 7.2k
- Fork
- 456
- Merge medio
- 16h 25m
- PR unite (30g)
- 30
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di netalertx/NetAlertX
-
bug 🐛 Contributors 🙏 help wanted 🆘
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
bug 🐛 next release/in dev image 🚀 Waiting for reply⏳
Difficoltà 3/5 Mezza giornata Idoneità per principianti 57/100
netalertx/NetAlertX#1852 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug 🐛 next release/in dev image 🚀 Waiting for reply⏳
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
netalertx/NetAlertX#1831 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Feature request ➕ please feedback 💬
Difficoltà 5/5 Più di una settimana Idoneità per principianti 45/100
netalertx/NetAlertX#1827 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Feature request ➕ please feedback 💬
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
netalertx/NetAlertX#1824 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di netalertx/NetAlertX
Issue simili
-
bug P1
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Toloka/tolokaforge#1947 ·
I maintainer di solito rispondono entro 1 giorno
-
SageMaker provider: streaming fails with NoStreamDataError on DJL Serving (LMI) endpointsForse già presa @balajiaru l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
UKGovernmentBEIS/inspect_ai#6127 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
pydot/pydot#601 · 4 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
letsencrypt/cp-cps#361 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100