~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix(security): replace innerHTML with DOM APIs to resolve XSS alerts (#3037)
LearningCircuitde2e547efc7b
diff --git a/src/local_deep_research/web/static/js/components/history.js b/src/local_deep_research/web/static/js/components/history.jsindex 4060eb13d4..5dff35d24a 100644--- a/src/local_deep_research/web/static/js/components/history.js+++ b/src/local_deep_research/web/static/js/components/history.js@@ -206,9 +206,12 @@// Update button labelconst btn = document.getElementById('search-mode-btn');- const labels = { hybrid: '<i class="fas fa-brain"></i> Hybrid', text: '<i class="fas fa-font"></i> Text Only', semantic: '<i class="fas fa-brain"></i> AI Only' };+ const iconMap = { hybrid: 'fa-brain', text: 'fa-font', semantic: 'fa-brain' };+ const labelMap = { hybrid: 'AI Hybrid', text: 'Text Only', semantic: 'AI Only' };const placeholders = { hybrid: 'Search titles + content...', text: 'Filter history by title...', semantic: 'Search content with AI...' };- if (btn) btn.innerHTML = labels[mode];+ if (btn && labelMap[mode]) {+ window.safeUpdateButton(btn, iconMap[mode], ' ' + labelMap[mode]);+ }if (searchInput) searchInput.placeholder = placeholders[mode];handleSearchInput();diff --git a/src/local_deep_research/web/static/js/components/library_search_ui.js b/src/local_deep_research/web/static/js/components/library_search_ui.jsindex 2bbe7d3fba..fa6acd160b 100644--- a/src/local_deep_research/web/static/js/components/library_search_ui.js+++ b/src/local_deep_research/web/static/js/components/library_search_ui.js@@ -42,10 +42,13 @@ if (searchModeMenu) {searchMode = mode;searchModeMenu.querySelectorAll('.dropdown-item').forEach(function(i) { i.classList.remove('active'); });item.classList.add('active');- var labels = { hybrid: '<i class="fas fa-brain" aria-hidden="true"></i> AI Hybrid', text: '<i class="fas fa-font" aria-hidden="true"></i> Text Only', semantic: '<i class="fas fa-brain" aria-hidden="true"></i> AI Only' };+ var icons = { hybrid: 'fa-brain', text: 'fa-font', semantic: 'fa-brain' };+ var labelTexts = { hybrid: 'AI Hybrid', text: 'Text Only', semantic: 'AI Only' };var placeholders = { hybrid: 'AI Hybrid: titles & authors + AI content search...', text: 'Text: filter by title, authors, DOI...', semantic: 'AI: search inside document content...' };var btn = document.getElementById('search-mode-btn');- if (btn) btn.innerHTML = labels[mode] || labels.hybrid;+ if (btn && labelTexts[mode]) {+ window.safeUpdateButton(btn, icons[mode], ' ' + labelTexts[mode]);+ }var input = document.getElementById('search-documents');if (input) input.placeholder = placeholders[mode] || placeholders.hybrid;// Clean up badges, snippets, and restore original card orderdiff --git a/src/local_deep_research/web/static/js/components/save_to_collection.js b/src/local_deep_research/web/static/js/components/save_to_collection.jsindex 10f3fa2db1..dba9fb3c8d 100644--- a/src/local_deep_research/web/static/js/components/save_to_collection.js+++ b/src/local_deep_research/web/static/js/components/save_to_collection.js@@ -8,15 +8,6 @@// URL security: This component uses centralized URLS.LIBRARY_API constants for API endpoints.// External URL validation is available via URLValidator.isSafeUrl if needed.- // Use shared escapeHtml from xss-protection.js (loaded via base.html),- // with a safe fallback if not available.- const escapeHtml = window.escapeHtml || function(text) {- if (text === null || text === undefined) return '';- const div = document.createElement('div');- div.textContent = String(text);- return div.innerHTML;- };-let modal = null;let researchId = null;@@ -122,20 +113,36 @@}// Build collection items- const html = collections.map(col => `- <button type="button" class="list-group-item list-group-item-action d-flex justify-content-between align-items-center"- data-collection-id="${escapeHtml(col.id)}"- data-collection-name="${escapeHtml(col.name)}">- <div>- <i class="fas fa-folder me-2"></i>- <strong>${escapeHtml(col.name)}</strong>- ${col.description ? `<br><small class="text-muted">${escapeHtml(col.description)}</small>` : ''}- </div>- <i class="fas fa-chevron-right text-muted"></i>- </button>- `).join('');+ itemsDiv.textContent = '';+ collections.forEach(col => {+ const button = document.createElement('button');+ button.type = 'button';+ button.className = 'list-group-item list-group-item-action d-flex justify-content-between align-items-center';+ button.dataset.collectionId = col.id;+ button.dataset.collectionName = col.name;++ const div = document.createElement('div');+ const folderIcon = document.createElement('i');+ folderIcon.className = 'fas fa-folder me-2';+ div.appendChild(folderIcon);+ const strong = document.createElement('strong');+ strong.textContent = col.name;+ div.appendChild(strong);+ if (col.description) {+ div.appendChild(document.createElement('br'));+ const small = document.createElement('small');+ small.className = 'text-muted';+ small.textContent = col.description;+ div.appendChild(small);+ }+ button.appendChild(div);- itemsDiv.innerHTML = html;+ const chevron = document.createElement('i');+ chevron.className = 'fas fa-chevron-right text-muted';+ button.appendChild(chevron);++ itemsDiv.appendChild(button);+ });// Attach click listeners via event delegation (avoids XSS from inline handlers)itemsDiv.querySelectorAll('button[data-collection-id]').forEach(btn => {@@ -155,19 +162,22 @@const errorDiv = document.getElementById('collection-error');const successDiv = document.getElementById('collection-success');- // Find and disable the clicked button (save original HTML for error recovery)+ // Find and disable the clicked button (save original children for error recovery)const buttons = itemsDiv.querySelectorAll('button');- let originalBtnHtml = null;+ let originalBtnChildren = null;buttons.forEach(btn => {btn.disabled = true;if (btn.dataset.collectionId === collectionId) {- originalBtnHtml = btn.innerHTML;- btn.innerHTML = `- <div>- <i class="fas fa-spinner fa-spin me-2"></i>- <strong>Saving...</strong>- </div>- `;+ originalBtnChildren = Array.from(btn.childNodes).map(n => n.cloneNode(true));+ btn.textContent = '';+ const spinDiv = document.createElement('div');+ const spinner = document.createElement('i');+ spinner.className = 'fas fa-spinner fa-spin me-2';+ spinDiv.appendChild(spinner);+ const savingText = document.createElement('strong');+ savingText.textContent = 'Saving...';+ spinDiv.appendChild(savingText);+ btn.appendChild(spinDiv);}});@@ -199,11 +209,19 @@}// Show success message- successDiv.innerHTML = `- <i class="fas fa-check-circle"></i>- Saved to <strong>${escapeHtml(collectionName)}</strong>!- <br><small>${escapeHtml(String(data.documents_added || 0))} documents added.</small>- `;+ successDiv.textContent = '';+ const checkIcon = document.createElement('i');+ checkIcon.className = 'fas fa-check-circle';+ successDiv.appendChild(checkIcon);+ successDiv.appendChild(document.createTextNode(' Saved to '));+ const nameStrong = document.createElement('strong');+ nameStrong.textContent = collectionName;+ successDiv.appendChild(nameStrong);+ successDiv.appendChild(document.createTextNode('!'));+ successDiv.appendChild(document.createElement('br'));+ const docsSmall = document.createElement('small');+ docsSmall.textContent = String(data.documents_added || 0) + ' documents added.';+ successDiv.appendChild(docsSmall);successDiv.style.display = 'block';// Re-enable buttons after a delay@@ -216,11 +234,12 @@errorDiv.textContent = error.message;errorDiv.style.display = 'block';- // Re-enable buttons and restore original HTML+ // Re-enable buttons and restore original contentbuttons.forEach(btn => {btn.disabled = false;- if (btn.dataset.collectionId === collectionId && originalBtnHtml) {- btn.innerHTML = originalBtnHtml;+ if (btn.dataset.collectionId === collectionId && originalBtnChildren) {+ btn.textContent = '';+ originalBtnChildren.forEach(node => btn.appendChild(node));}});}diff --git a/src/local_deep_research/web/static/js/pages/news.js b/src/local_deep_research/web/static/js/pages/news.jsindex a421ae794a..aa3e36006f 100644--- a/src/local_deep_research/web/static/js/pages/news.js+++ b/src/local_deep_research/web/static/js/pages/news.js@@ -2113,7 +2113,9 @@ function setupSearchModeToggle() {if (btn) {const labels = { hybrid: 'AI Hybrid', text: 'Text Only', semantic: 'AI Only' };const icons = { hybrid: 'fa-brain', text: 'fa-font', semantic: 'fa-brain' };- btn.innerHTML = `<i class="fas ${icons[mode]}"></i> ${labels[mode]}`;+ if (labels[mode]) {+ window.safeUpdateButton(btn, icons[mode], ' ' + labels[mode]);+ }}// Update placeholderdiff --git a/src/local_deep_research/web/static/js/security/xss-protection.js b/src/local_deep_research/web/static/js/security/xss-protection.jsindex 9d9202cd32..656a2d80ef 100644--- a/src/local_deep_research/web/static/js/security/xss-protection.js+++ b/src/local_deep_research/web/static/js/security/xss-protection.js@@ -354,9 +354,10 @@ function sanitizeUserInput(input, options = {}) {button.removeChild(button.firstChild);}- // Create icon+ // Create icon (aria-hidden for accessibility — decorative icons beside text)const icon = document.createElement('i');icon.className = `fas ${iconClass}`;+ icon.setAttribute('aria-hidden', 'true');if (addSpinner) {icon.className += ' fa-spin';}diff --git a/src/local_deep_research/web/templates/pages/history.html b/src/local_deep_research/web/templates/pages/history.htmlindex 24fa698f28..512ee04e3b 100644--- a/src/local_deep_research/web/templates/pages/history.html+++ b/src/local_deep_research/web/templates/pages/history.html@@ -57,17 +57,17 @@<div class="dropdown d-inline-block"><button class="btn btn-sm ldr-btn-outline dropdown-toggle" type="button"id="search-mode-btn" data-bs-toggle="dropdown" aria-expanded="false">- <i class="fas fa-brain"></i> AI Hybrid+ <i class="fas fa-brain" aria-hidden="true"></i> AI Hybrid</button><ul class="dropdown-menu" aria-label="Search mode" id="search-mode-menu"><li><a class="dropdown-item active" href="#" data-mode="hybrid">- <i class="fas fa-brain"></i> AI Hybrid <small class="text-muted">— titles + content</small>+ <i class="fas fa-brain" aria-hidden="true"></i> AI Hybrid <small class="text-muted">— titles + content</small></a></li><li><a class="dropdown-item" href="#" data-mode="text">- <i class="fas fa-font"></i> Text Only <small class="text-muted">— titles only</small>+ <i class="fas fa-font" aria-hidden="true"></i> Text Only <small class="text-muted">— titles only</small></a></li><li><a class="dropdown-item" href="#" data-mode="semantic">- <i class="fas fa-brain"></i> AI Only <small class="text-muted">— content search</small>+ <i class="fas fa-brain" aria-hidden="true"></i> AI Only <small class="text-muted">— content search</small></a></li></ul></div>