Skip to content

🛡️ Warracker is an open source, self-hostable warranty tracker to monitor expirations, store receipts, files. You own the data, your rules!

Security: fix three stored-XSS sinks (admin Users table, document links, legacy edit modal)

Omega (QA)e1ac268b4d58
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b9c1c70..17d9692 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -40,6 +40,9 @@
- **Other documents accept more than archives (#222):** the Other Document file picker in the add form and both edit modals only offered ZIP/RAR files, even though the server has always accepted PDFs and images there too — so a warranty terms PDF could not be attached through the UI. The picker now offers every type the server accepts (PDF, PNG, JPG, WebP, GIF, ZIP, RAR), and the field label no longer calls out only archives (all 20 locales).
- _Files: `frontend/index.html`, `frontend/status.html`, `locales/en/translation.json`_
+- **Stored XSS fixes in the admin user list, document links, and the legacy edit modal (security):** three places rendered stored, user-controlled values into pages without safe encoding. The admin Users table in Settings now renders usernames as plain text, with the owner crown built as a DOM element, so a crafted username can no longer run script in an admin's browser when Settings loads. Warranty document links now pass the stored document URL through the same escaping and dangerous-scheme blocking the product link already used, so a quote stored in a document URL can no longer break out of the link's href attribute. The legacy edit modal shared by the main and status pages now fills serial number inputs through the input value property instead of interpolating serials into the markup, so a serial containing a quote can no longer break out of its attribute when a warranty is opened for editing under global view. Labels, icons, and layout are unchanged.
+ - _Files: `frontend/settings-new.js`, `frontend/js/components/warrantyRenderer.js`, `frontend/script.js`, `tests/test_xss_regressions.py`_
+
# 1.0.4 - 2026-10-31
- **Claim documents (issue #148):** claims can now carry documents — claim approval or rejection letters, photos of the defect, repair invoices, and similar evidence. Each claim shows a Documents section in the claims view: attach a file directly, or upload it to Paperless-ngx and link it, then view or remove it from the same place. Access follows the warranty's other documents: the owner and admins only, never shared through global view. Deleting a claim or its warranty removes the attached local files from disk; Paperless documents are unlinked, never deleted from Paperless.
diff --git a/frontend/js/components/warrantyRenderer.js b/frontend/js/components/warrantyRenderer.js
index 3ff2776..3c8fbaa 100644
--- a/frontend/js/components/warrantyRenderer.js
+++ b/frontend/js/components/warrantyRenderer.js
@@ -279,7 +279,7 @@ function generateDocumentLink(warranty, docType) {
if (hasUrl) {
if (linksHtml) linksHtml += ' ';
- linksHtml += `<a href="${config.url}" target="_blank" class="document-url-link ${config.className}">
+ linksHtml += `<a href="${escapeHtml(sanitizeUrl(config.url))}" target="_blank" rel="noopener noreferrer" class="document-url-link ${config.className}">
<i class="fas fa-link"></i> ${config.label} ${t('warranties.link', 'Link')}
</a>`;
}
diff --git a/frontend/script.js b/frontend/script.js
index a656706..4795972 100644
--- a/frontend/script.js
+++ b/frontend/script.js
@@ -2491,14 +2491,19 @@ async function openEditModal(warranty) {
addSerialNumberInput(editSerialNumbersContainer);
} else {
// Add the first serial number with an "Add Another" button only (no remove button)
+ // The serial value is assigned through the input's value property, never
+ // interpolated into innerHTML: a serial containing a quote could otherwise
+ // break out of the value attribute (stored XSS, e.g. via the status page's
+ // edit modal under global view).
const firstInput = document.createElement('div');
firstInput.className = 'serial-number-input';
firstInput.innerHTML = `
- <input type="text" name="serial_numbers[]" class="form-control" placeholder="${i18next.t('warranties.enter_serial_number')}" value="${validSerialNumbers[0]}">
+ <input type="text" name="serial_numbers[]" class="form-control" placeholder="${i18next.t('warranties.enter_serial_number')}">
<button type="button" class="btn btn-sm btn-primary add-serial-number">
<i class="fas fa-plus"></i> ${i18next.t('warranties.add_serial_number')}
</button>
`;
+ firstInput.querySelector('input').value = validSerialNumbers[0];
// Add event listener for the Add button
firstInput.querySelector('.add-serial-number').addEventListener('click', function(e) {
@@ -2513,11 +2518,12 @@ async function openEditModal(warranty) {
const newInput = document.createElement('div');
newInput.className = 'serial-number-input';
newInput.innerHTML = `
- <input type="text" name="serial_numbers[]" class="form-control" placeholder="${i18next.t('warranties.enter_serial_number')}" value="${validSerialNumbers[i]}">
+ <input type="text" name="serial_numbers[]" class="form-control" placeholder="${i18next.t('warranties.enter_serial_number')}">
<button type="button" class="btn btn-sm btn-danger remove-serial-number">
<i class="fas fa-minus"></i> ${i18next.t('actions.delete')}
</button>
`;
+ newInput.querySelector('input').value = validSerialNumbers[i];
// Add remove button functionality
newInput.querySelector('.remove-serial-number').addEventListener('click', function() {
diff --git a/frontend/settings-new.js b/frontend/settings-new.js
index 3e38d1f..4f03276 100644
--- a/frontend/settings-new.js
+++ b/frontend/settings-new.js
@@ -2069,11 +2069,19 @@ async function loadUsers() {
idCell.style.cssText = 'padding: 12px 8px; color: var(--text-color); border-right: 1px solid var(--border-color); font-weight: 500;';
row.appendChild(idCell);
- // Username with crown
+ // Username with crown. The username is user-controlled, so it
+ // is rendered as text, never via innerHTML (stored-XSS fix);
+ // the owner crown is built as a DOM node for the same reason.
const usernameCell = document.createElement('td');
- const crownIcon = user.is_owner ? ' <i class="fas fa-crown" title="Application Owner" style="color: #f39c12; margin-left: 5px;"></i>' : '';
console.log(`DEBUG: User ${user.username} (ID: ${user.id}) - is_owner: ${user.is_owner}, adding crown: ${!!user.is_owner}`);
- usernameCell.innerHTML = user.username + crownIcon;
+ usernameCell.textContent = user.username;
+ if (user.is_owner) {
+ const crownIcon = document.createElement('i');
+ crownIcon.className = 'fas fa-crown';
+ crownIcon.title = 'Application Owner';
+ crownIcon.style.cssText = 'color: #f39c12; margin-left: 5px;';
+ usernameCell.appendChild(crownIcon);
+ }
usernameCell.style.cssText = 'padding: 12px 8px; color: var(--text-color); border-right: 1px solid var(--border-color); font-weight: 500;';
row.appendChild(usernameCell);
diff --git a/tests/test_xss_regressions.py b/tests/test_xss_regressions.py
new file mode 100644
index 0000000..0f06723
--- /dev/null
+++ b/tests/test_xss_regressions.py
@@ -0,0 +1,51 @@
+"""Regression pins for the 1.0.5 stored-XSS fixes (audit XSS-01/02/04A).
+
+The vulnerable sinks are frontend rendering paths, so these tests pin
+the safe rendering patterns in the shipped sources: if anyone puts the
+raw interpolation back, the suite fails before the payload does.
+
+- XSS-01: the admin Users table rendered `user.username` through
+ innerHTML. A crafted username executed in an admin's browser as soon
+ as Settings loaded. The username must be assigned via textContent,
+ with the owner crown built as a DOM node.
+- XSS-02: card document links interpolated the stored document URL
+ straight into an href attribute, so a quote in the URL broke out of
+ the attribute. The URL must go through the renderer's established
+ escapeHtml(sanitizeUrl(...)) path, like the product link already did.
+- XSS-04A: the legacy edit modal (the only edit modal on the status
+ page) interpolated serial numbers into an input's value attribute.
+ Serials must be assigned through the input's value property. Note
+ script.js's global escapeHtml is shadowed by a quote-less variant,
+ so escaping alone is not sufficient protection in attribute context.
+"""
+import os
+
+REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+
+
+def _read(relpath):
+ with open(os.path.join(REPO_ROOT, relpath), encoding="utf-8") as fh:
+ return fh.read()
+
+
+def test_xss01_username_rendered_as_text_not_innerhtml():
+ src = _read("frontend/settings-new.js")
+ assert "usernameCell.textContent = user.username" in src
+ assert "usernameCell.innerHTML = user.username" not in src
+ # Crown preserved, but as a DOM node rather than an HTML string.
+ assert "document.createElement('i')" in src
+ assert "crownIcon.className = 'fas fa-crown'" in src
+
+
+def test_xss02_document_url_escaped_and_sanitized():
+ src = _read("frontend/js/components/warrantyRenderer.js")
+ assert "escapeHtml(sanitizeUrl(config.url))" in src
+ assert 'href="${config.url}"' not in src
+
+
+def test_xss04a_edit_modal_serials_assigned_via_value_property():
+ src = _read("frontend/script.js")
+ assert 'value="${validSerialNumbers[' not in src
+ assert ".value = validSerialNumbers[0]" in src
+ assert ".value = validSerialNumbers[i]" in src
+