🛡️ Warracker is an open source, self-hostable warranty tracker to monitor expirations, store receipts, files. You own the data, your rules!
Security: build the wizard serial summary as DOM nodes, not markup (XSS-09)
Omega (QA)db9f45d74509
diff --git a/frontend/js/components/addWarrantyForm.js b/frontend/js/components/addWarrantyForm.jsindex 79cefe7..2da28c2 100644--- a/frontend/js/components/addWarrantyForm.js+++ b/frontend/js/components/addWarrantyForm.js@@ -391,7 +391,18 @@ export function updateSummary() {.filter(Boolean);if (state.summary.serialNumbers) {if (serialValues.length) {- state.summary.serialNumbers.innerHTML = `<ul>${serialValues.map((sn) => `<li>${sn}</li>`).join('')}</ul>`;+ // Build the list with DOM APIs, not innerHTML: serial+ // numbers are the user's own unsaved input, and reflecting+ // them as markup executed typed payloads when the summary+ // rendered (XSS-09). textContent keeps them inert.+ state.summary.serialNumbers.innerHTML = '';+ const list = document.createElement('ul');+ serialValues.forEach((sn) => {+ const item = document.createElement('li');+ item.textContent = sn;+ list.appendChild(item);+ });+ state.summary.serialNumbers.appendChild(list);} else {state.summary.serialNumbers.textContent = (window.i18next && window.i18next.t('warranties.none') || 'None');}diff --git a/frontend/js/components/formTabs.js b/frontend/js/components/formTabs.jsindex 25eeef7..cfc0788 100644--- a/frontend/js/components/formTabs.js+++ b/frontend/js/components/formTabs.js@@ -254,9 +254,18 @@ function updateSummary() {const serialNumbersContainer = document.getElementById('summary-serial-numbers');if (serialNumbersContainer) {if (serialNumbers.length > 0) {- serialNumbersContainer.innerHTML = '<ul>' +- serialNumbers.map(sn => `<li>${sn}</li>`).join('') +- '</ul>';+ // Build the list with DOM APIs, not innerHTML: serial+ // numbers are the user's own unsaved input, and reflecting+ // them as markup executed typed payloads when the summary+ // step rendered (XSS-09). textContent keeps them inert.+ serialNumbersContainer.innerHTML = '';+ const list = document.createElement('ul');+ serialNumbers.forEach(sn => {+ const item = document.createElement('li');+ item.textContent = sn;+ list.appendChild(item);+ });+ serialNumbersContainer.appendChild(list);} else {serialNumbersContainer.textContent = 'None';}diff --git a/tests/test_xss_regressions.py b/tests/test_xss_regressions.pyindex 717a4fe..09df5df 100644--- a/tests/test_xss_regressions.py+++ b/tests/test_xss_regressions.py@@ -32,6 +32,10 @@ raw interpolation back, the suite fails before the payload does.owner's browser. The test-connection and test-upload renders carrythe same server-controlled strings. All of them must go through thefile's escapeHtmlSafe helper.+- XSS-09: the add-warranty wizard's summary step interpolated the+ user's own unsaved serial numbers raw into innerHTML, so a typed+ payload executed when the summary rendered. The list must be built+ with DOM APIs and textContent."""import os@@ -127,3 +131,19 @@ def test_xss08_paperless_test_renders_escaped():assert "${escapeHtmlSafe(result.message)}" in uploadassert "${escapeHtmlSafe(result.error)}" in upload++def test_xss09_wizard_summary_serials_built_as_dom_nodes():+ src = _read("frontend/js/components/formTabs.js")+ assert "<li>${sn}</li>" not in src+ assert "serialNumbers.map(sn =>" not in src+ assert "document.createElement('ul')" in src+ assert "document.createElement('li')" in src+ assert "item.textContent = sn" in src+ # The live summary render is addWarrantyForm.js's updateSummary,+ # which carried the same raw interpolation; both copies are pinned.+ live = _read("frontend/js/components/addWarrantyForm.js")+ assert "<li>${sn}</li>" not in live+ assert "serialValues.map((sn) =>" not in live+ assert "document.createElement('ul')" in live+ assert "item.textContent = sn" in live+