~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
refactor: consolidate escapeHtml implementations with fallback pattern (#2019)
LearningCircuit16c1eadcd479
diff --git a/src/local_deep_research/web/static/js/collection_details.js b/src/local_deep_research/web/static/js/collection_details.jsindex a25135f77b..8f2b250808 100644--- a/src/local_deep_research/web/static/js/collection_details.js+++ b/src/local_deep_research/web/static/js/collection_details.js@@ -506,14 +506,12 @@ function formatBytes(bytes) {}/**- * Escape HTML to prevent XSS+ * Fallback HTML escape function (used if xss-protection.js fails to load)*/-function escapeHtml(text) {- if (!text) return '';- const div = document.createElement('div');- div.textContent = text;- return div.innerHTML;-}+const escapeHtmlFallback = (str) => String(str || '').replace(/[&<>"']/g, (m) => ({'&':'&','<':'<','>':'>','"':'"',"'":'''})[m]);++// Use global escapeHtml from xss-protection.js with fallback+const escapeHtml = window.escapeHtml || escapeHtmlFallback;/*** Show success messagediff --git a/src/local_deep_research/web/static/js/collection_upload.js b/src/local_deep_research/web/static/js/collection_upload.jsindex 209d9df27a..89eb74dd3b 100644--- a/src/local_deep_research/web/static/js/collection_upload.js+++ b/src/local_deep_research/web/static/js/collection_upload.js@@ -18,15 +18,14 @@ async function safeFetch(url, options = {}) {}/**- * Escape HTML special characters to prevent XSS attacks+ * Fallback HTML escape function (used if xss-protection.js fails to load)* @param {string} text - Text to escape* @returns {string} - Escaped text safe for HTML insertion*/-function escapeHtml(text) {- const div = document.createElement('div');- div.textContent = text;- return div.innerHTML;-}+const escapeHtmlFallback = (str) => String(str).replace(/[&<>"']/g, (m) => ({'&':'&','<':'<','>':'>','"':'"',"'":'''})[m]);++// Use global escapeHtml from xss-protection.js with fallback+const escapeHtml = window.escapeHtml || escapeHtmlFallback;// Store selected files globally to avoid losing themlet selectedFiles = [];diff --git a/src/local_deep_research/web/static/js/collections_manager.js b/src/local_deep_research/web/static/js/collections_manager.jsindex 73020ddde1..5408c64a3f 100644--- a/src/local_deep_research/web/static/js/collections_manager.js+++ b/src/local_deep_research/web/static/js/collections_manager.js@@ -242,14 +242,12 @@ function formatBytes(bytes) {}/**- * Escape HTML to prevent XSS+ * Fallback HTML escape function (used if xss-protection.js fails to load)*/-function escapeHtml(text) {- if (!text) return '';- const div = document.createElement('div');- div.textContent = text;- return div.innerHTML;-}+const escapeHtmlFallback = (str) => String(str || '').replace(/[&<>"']/g, (m) => ({'&':'&','<':'<','>':'>','"':'"',"'":'''})[m]);++// Use global escapeHtml from xss-protection.js with fallback+const escapeHtml = window.escapeHtml || escapeHtmlFallback;/*** Show success messagediff --git a/src/local_deep_research/web/static/js/components/detail.js b/src/local_deep_research/web/static/js/components/detail.jsindex 3a3d353d06..13264c382c 100644--- a/src/local_deep_research/web/static/js/components/detail.js+++ b/src/local_deep_research/web/static/js/components/detail.js@@ -709,15 +709,12 @@}/**- * Escape HTML to prevent XSS- * @param {string} text - Text to escape- * @returns {string} Escaped text+ * Fallback HTML escape function (used if xss-protection.js fails to load)*/- function escapeHtml(text) {- const div = document.createElement('div');- div.textContent = text;- return div.innerHTML;- }+ const escapeHtmlFallback = (str) => String(str || '').replace(/[&<>"']/g, (m) => ({'&':'&','<':'<','>':'>','"':'"',"'":'''})[m]);++ // Use global escapeHtml from xss-protection.js with fallback+ const escapeHtml = window.escapeHtml || escapeHtmlFallback;// Clean up on page unloadwindow.addEventListener('beforeunload', function() {diff --git a/src/local_deep_research/web/static/js/components/settings.js b/src/local_deep_research/web/static/js/components/settings.jsindex 126f81414c..41e5a83654 100644--- a/src/local_deep_research/web/static/js/components/settings.js+++ b/src/local_deep_research/web/static/js/components/settings.js@@ -40,19 +40,15 @@const CACHE_EXPIRATION = 24 * 60 * 60 * 1000;/**- * Escape HTML to prevent XSS attacks- * @param {string} unsafe - Text to escape- * @returns {string} Escaped text+ * Fallback HTML escape function (used if xss-protection.js fails to load)*/- function escapeHtml(unsafe) {- if (unsafe === null || unsafe === undefined) return '';- return String(unsafe)- .replace(/&/g, "&")- .replace(/</g, "<")- .replace(/>/g, ">")- .replace(/"/g, """)- .replace(/'/g, "'");- }+ const escapeHtmlFallback = (str) => {+ if (str === null || str === undefined) return '';+ return String(str).replace(/[&<>"']/g, (m) => ({'&':'&','<':'<','>':'>','"':'"',"'":'''})[m]);+ };++ // Use global escapeHtml from xss-protection.js with fallback+ const escapeHtml = window.escapeHtml || escapeHtmlFallback;/*** Helper function to generate custom dropdown HTML (similar to Jinja macro)@@ -1546,9 +1542,8 @@`;} else {// Sanitize data directory path to prevent XSS- // Inline fallback ensures escaping even if xss-protection.js fails to load- const escapeHtmlFallback = (str) => String(str).replace(/[&<>"']/g, (m) => ({'&':'&','<':'<','>':'>','"':'"',"'":'''})[m]);- const safeDataDirCompact = (window.escapeHtml || escapeHtmlFallback)(data.data_directory);+ // Use escapeHtml (defined at top of IIFE with fallback)+ const safeDataDirCompact = escapeHtml(data.data_directory);html += `<div class="data-location-compact">diff --git a/src/local_deep_research/web/static/js/deletion/confirmation_modal.js b/src/local_deep_research/web/static/js/deletion/confirmation_modal.jsindex 53ae024500..8ff37c7df8 100644--- a/src/local_deep_research/web/static/js/deletion/confirmation_modal.js+++ b/src/local_deep_research/web/static/js/deletion/confirmation_modal.js@@ -200,13 +200,12 @@ function hideDeleteModal() {}/**- * Escape HTML to prevent XSS+ * Fallback HTML escape function (used if xss-protection.js fails to load)*/-function escapeHtml(text) {- const div = document.createElement('div');- div.textContent = text;- return div.innerHTML;-}+const escapeHtmlFallback = (str) => String(str || '').replace(/[&<>"']/g, (m) => ({'&':'&','<':'<','>':'>','"':'"',"'":'''})[m]);++// Use global escapeHtml from xss-protection.js with fallback+const escapeHtml = window.escapeHtml || escapeHtmlFallback;/*** Get tooltip text for an actiondiff --git a/src/local_deep_research/web/static/js/embedding_settings.js b/src/local_deep_research/web/static/js/embedding_settings.jsindex 3194f32222..cd020e123f 100644--- a/src/local_deep_research/web/static/js/embedding_settings.js+++ b/src/local_deep_research/web/static/js/embedding_settings.js@@ -570,13 +570,12 @@ function showError(message) {}/**- * Escape HTML to prevent XSS+ * Fallback HTML escape function (used if xss-protection.js fails to load)*/-function escapeHtml(text) {- const div = document.createElement('div');- div.textContent = text;- return div.innerHTML;-}+const escapeHtmlFallback = (str) => String(str || '').replace(/[&<>"']/g, (m) => ({'&':'&','<':'<','>':'>','"':'"',"'":'''})[m]);++// Use global escapeHtml from xss-protection.js with fallback+const escapeHtml = window.escapeHtml || escapeHtmlFallback;/*** Toggle Ollama URL field visibility based on selected provider