π‘οΈ Warracker is an open source, self-hostable warranty tracker to monitor expirations, store receipts, files. You own the data, your rules!
Fix stored XSS in warranty card rendering; credit security reporters
Omega (QA)a1ced8b69f5d
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex cee6f09..f3fcdf8 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -13,6 +13,8 @@- _Files: `frontend/js/components/tagManager.js`_### Fixed+- **Stored XSS via warranty fields fixed (reported by lazymaster101 and the CSCE 413 Texas A&M team):** warranty cards rendered `product_name`, `vendor`, `model_number`, `warranty_type`, tag names, serial numbers, and the user display name into `innerHTML` without escaping, so a malicious value (e.g. injected through CSV import) executed JavaScript in every viewer's browser. All user-controlled fields are now HTML-escaped before rendering (quotes included, so attribute contexts are safe too), and `product_url` links now also reject `javascript:`/`data:`/`vbscript:` schemes. Verified with live payloads (`<img onerror>`, `<svg onload>`, attribute breakout, `javascript:` URL, malicious tag name) β all render as inert text. Credit: reported via responsible disclosure by [lazymaster101](https://github.com/lazymaster101) and the CSCE 413 (Texas A&M University) vulnerability-research team β Carrigan Royer, Jayani Singh, Seshadithya Saravanan, Aaditya Srinivasan, Miko Quinones.+ - _Files: `frontend/js/components/warrantyRenderer.js`, `frontend/js/components/claims.js`, `frontend/status.js`_- **Input validations are now enforced and translated:** three new HTTP 400 validations β product name over 255 chars (was an unhandled DB error β HTTP 500), expiration date before purchase date (was silently accepted), and invalid claim status (was silently coerced) β now return a stable machine-readable `code` (`product_name_too_long`, `expiration_before_purchase`, `invalid_claim_status`; claim-status errors also include `valid_statuses`) alongside the English fallback message. The frontend maps those codes to i18n keys via a new `apiErrorMessage()` helper in `ui.js` (used by the add-warranty form, edit modal, and claims toasts), so error toasts render in the user's language instead of always-English. Two new English keys were added (`messages.product_name_too_long`, `messages.invalid_claim_status`) and machine-translated into all 19 non-English locales with `{{statuses}}` placeholder integrity verified. Also removed the now-unused `safeErrorMessage()` helper from `apiService.js`.- _Files: `backend/warranties_routes.py`, `frontend/js/components/ui.js`, `frontend/js/services/apiService.js`, `frontend/js/components/addWarrantyForm.js`, `frontend/js/components/editModal.js`, `frontend/js/components/claims.js`, `locales/*/translation.json`_- **Expiry-day inconsistency fixed:** a warranty expiring *today* got three different answers β statistics counted it as `expired` (`expiration_date <= today`), the UI showed "expiring" (0 days left), and the notification query excluded it (`expiration_date > today`). All three now agree it is still valid: statistics uses `expiration_date < today` for expired and `>= today` for the active / expiring-soon / timeline buckets, and the expiry notification query includes it (`>= today`).diff --git a/README.md b/README.mdindex aecf790..95d3aa0 100644--- a/README.md+++ b/README.md@@ -321,6 +321,9 @@ This project is licensed under the GNU Affero General Public License v3.0 - see* Apprise* i18next+### Security researchers+* [lazymaster101](https://github.com/lazymaster101) and the CSCE 413 (Texas A&M University) vulnerability-research team β Carrigan Royer, Jayani Singh, Seshadithya Saravanan, Aaditya Srinivasan, Miko Quinones β for the responsible disclosure of a stored XSS vulnerability.+## βStar History<a href="https://star-history.com/#sassanix/Warracker&Date">diff --git a/frontend/js/components/claims.js b/frontend/js/components/claims.jsindex e8f410f..9b40c0a 100644--- a/frontend/js/components/claims.js+++ b/frontend/js/components/claims.js@@ -122,9 +122,9 @@ function updateWarrantyInfo(warranty) {const statusText = warranty.statusText || t('warranties.unknown_status', 'Unknown Status');dom.warrantyClaimInfo.innerHTML = `<div class="warranty-info-card">- <h4>${warranty.product_name || t('warranties.unnamed_product', 'Unnamed Product')}</h4>+ <h4>${escapeHtml(warranty.product_name || t('warranties.unnamed_product', 'Unnamed Product'))}</h4><div class="warranty-details">- <span><i class="fas fa-building"></i> ${vendorLabel}</span>+ <span><i class="fas fa-building"></i> ${escapeHtml(vendorLabel)}</span><span><i class="fas fa-calendar"></i> ${expiresLabel}</span><span class="warranty-status status-${statusClass}">${statusText}diff --git a/frontend/js/components/warrantyRenderer.js b/frontend/js/components/warrantyRenderer.jsindex 25255c5..6ac4638 100644--- a/frontend/js/components/warrantyRenderer.js+++ b/frontend/js/components/warrantyRenderer.js@@ -38,6 +38,22 @@ const t = (key, fallback, options) => {}};+// Escape user-controlled strings before injecting into innerHTML templates+// (stored-XSS defense; safe for both element content and attribute contexts).+const escapeHtml = (text) => {+ if (text === null || text === undefined) return '';+ return String(text).replace(/[&<>"']/g, (s) => ({+ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''',+ }[s]));+};++// Block javascript:/data:/vbscript: URLs in href attributes.+const sanitizeUrl = (url) => {+ const s = String(url || '').trim();+ if (/^\s*(javascript|data|vbscript)\s*:/i.test(s)) return '#';+ return s;+};+function getContrastColor(hexColor) {if (!hexColor) return '#ffffff';const hex = hexColor.replace('#', '');@@ -152,8 +168,8 @@ function buildTagsHtml(tags = []) {return `<div class="tags-row">${tags.map((tag) => `- <span class="tag" style="background-color: ${tag.color}; color: ${getContrastColor(tag.color)}">- ${tag.name}+ <span class="tag" style="background-color: ${escapeHtml(tag.color)}; color: ${getContrastColor(tag.color)}">+ ${escapeHtml(tag.name)}</span>`).join('')}</div>@@ -174,7 +190,7 @@ function buildDocumentLinks(warranty, notesLinkHtml) {const links = [];if (warranty.product_url) {links.push(`- <a href="${warranty.product_url}" class="product-link" target="_blank">+ <a href="${escapeHtml(sanitizeUrl(warranty.product_url))}" class="product-link" target="_blank" rel="noopener noreferrer"><i class="fas fa-globe"></i> ${t('warranties.product_website', 'Product Website')}</a>`);@@ -289,13 +305,13 @@ function buildSerialNumberHtml(serialNumbers = []) {? `<div style="margin-left: 28px;"><ul style="margin-top: 5px;">- ${rest.map((sn) => `<li>${sn}</li>`).join('')}+ ${rest.map((sn) => `<li>${escapeHtml(sn)}</li>`).join('')}</ul></div>`: '';return `- <div><i class="fas fa-barcode"></i> ${label}: <span>${first}</span></div>+ <div><i class="fas fa-barcode"></i> ${label}: <span>${escapeHtml(first)}</span></div>${extra}`;}@@ -303,7 +319,7 @@ function buildSerialNumberHtml(serialNumbers = []) {function buildUserInfo(warranty, isGlobalView) {if (!isGlobalView || !warranty.user_display_name) return '';const ownerLabel = t('warranties.owner', 'Owner');- return `<div><strong>${ownerLabel}:</strong> <span>${warranty.user_display_name}</span></div>`;+ return `<div><strong>${ownerLabel}:</strong> <span>${escapeHtml(warranty.user_display_name)}</span></div>`;}function resolveCanEdit(warranty, isGlobalView) {@@ -396,9 +412,9 @@ function buildInfoBlock(warranty, { userInfoHtml, productAge, warrantyDurationTe`<div><i class="fas fa-wrench"></i> ${t('warranties.warranty_ends', 'Warranty Ends')}: <span>${expirationDateText}</span></div>`,priceHtml,serialsHtml,- warranty.model_number ? `<div><i class="fas fa-tag"></i> ${t('warranties.model_number', 'Model Number')}: <span>${warranty.model_number}</span></div>` : '',- warranty.vendor ? `<div><i class="fas fa-store"></i> ${t('warranties.vendor', 'Vendor')}: <span>${warranty.vendor}</span></div>` : '',- warranty.warranty_type ? `<div><i class="fas fa-shield-alt"></i> ${t('warranties.type', 'Type')}: <span>${warranty.warranty_type}</span></div>` : '',+ warranty.model_number ? `<div><i class="fas fa-tag"></i> ${t('warranties.model_number', 'Model Number')}: <span>${escapeHtml(warranty.model_number)}</span></div>` : '',+ warranty.vendor ? `<div><i class="fas fa-store"></i> ${t('warranties.vendor', 'Vendor')}: <span>${escapeHtml(warranty.vendor)}</span></div>` : '',+ warranty.warranty_type ? `<div><i class="fas fa-shield-alt"></i> ${t('warranties.type', 'Type')}: <span>${escapeHtml(warranty.warranty_type)}</span></div>` : '',];return pieces.filter(Boolean).join('');}@@ -413,7 +429,7 @@ function buildCardInnerHtml(view, warranty, derived) {`;const base = `<div class="product-name-header">- <h3 class="warranty-title" title="${warranty.product_name || 'Unnamed Product'}">${warranty.product_name || 'Unnamed Product'}</h3>+ <h3 class="warranty-title" title="${escapeHtml(warranty.product_name || 'Unnamed Product')}">${escapeHtml(warranty.product_name || 'Unnamed Product')}</h3><div class="warranty-actions">${derived.actionButtons}</div>diff --git a/frontend/status.js b/frontend/status.jsindex 162f1d2..bd643b4 100644--- a/frontend/status.js+++ b/frontend/status.js@@ -909,7 +909,7 @@let dHtml = '<div class="warranty-details-content" style="display: flex; flex-wrap: wrap; gap: 20px;">';dHtml += '<div style="flex: 1 1 300px;"><h4>Core Information</h4>';- dHtml += `<p><strong>Product URL:</strong> ${warrantyDetails.product_url ? `<a href="${warrantyDetails.product_url}" target="_blank" rel="noopener noreferrer">${escapeHTML(warrantyDetails.product_url)}</a>` : 'N/A'}</p>`;+ dHtml += `<p><strong>Product URL:</strong> ${warrantyDetails.product_url ? `<a href="${escapeHTML(String(warrantyDetails.product_url).trim().replace(/^\s*(javascript|data|vbscript)\s*:/i, '#'))}" target="_blank" rel="noopener noreferrer">${escapeHTML(warrantyDetails.product_url)}</a>` : 'N/A'}</p>`;dHtml += `<p><strong>Purchase Price:</strong> ${warrantyDetails.purchase_price !== null && warrantyDetails.purchase_price !== undefined ? escapeHTML(userCurrencySymbol) + parseFloat(warrantyDetails.purchase_price).toFixed(2) : 'N/A'}</p>`;dHtml += `<p><strong>Vendor:</strong> ${escapeHTML(warrantyDetails.vendor || '') || 'N/A'}</p>`;dHtml += `<p><strong>Warranty Type:</strong> ${escapeHTML(warrantyDetails.warranty_type || '') || 'N/A'}</p></div>`;