~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: Enable dynamic DOMPurify detection for dropdown highlighting
LearningCircuitdbd2e71b3643
diff --git a/.github/workflows/infrastructure-tests.yml b/.github/workflows/infrastructure-tests.ymlindex 556f41034f..dac7de56d0 100644--- a/.github/workflows/infrastructure-tests.yml+++ b/.github/workflows/infrastructure-tests.yml@@ -5,12 +5,14 @@ on:paths:- 'src/local_deep_research/web/routes/**'- 'src/local_deep_research/web/static/js/config/**'+ - 'src/local_deep_research/web/static/js/security/**'- 'tests/infrastructure_tests/**'- '.github/workflows/infrastructure-tests.yml'pull_request:paths:- 'src/local_deep_research/web/routes/**'- 'src/local_deep_research/web/static/js/config/**'+ - 'src/local_deep_research/web/static/js/security/**'- 'tests/infrastructure_tests/**'- '.github/workflows/infrastructure-tests.yml'diff --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 aed271cb3c..4034e89e09 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@@ -9,8 +9,11 @@(function() {'use strict';- // Check if DOMPurify is available (should be loaded via app.js/Vite)- const hasDOMPurify = typeof DOMPurify !== 'undefined';+ // Check if DOMPurify is available dynamically (loaded via app.js/Vite module)+ // Must be a function since Vite modules are deferred and load after this script+ function hasDOMPurify() {+ return typeof DOMPurify !== 'undefined';+ }/*** HTML entity encoding map for XSS prevention@@ -33,7 +36,7 @@ALLOW_DATA_ATTR: false,FORBID_TAGS: ['script', 'iframe', 'object', 'embed', 'form', 'input', 'button', 'style', 'meta', 'link'],FORBID_ATTR: ['onerror', 'onload', 'onclick', 'onmouseover', 'onfocus', 'onblur', 'onchange', 'onsubmit', 'on*'],- KEEP_CONTENT: false,+ KEEP_CONTENT: true,SANITIZE_DOM: true,SANITIZE_NAMED_PROPS: true,SAFE_FOR_TEMPLATES: true,@@ -88,7 +91,7 @@ function safeSetInnerHTML(element, content, allowHtmlTags = false) {const contentString = String(content);- if (allowHtmlTags && hasDOMPurify) {+ if (allowHtmlTags && hasDOMPurify()) {// Use DOMPurify for secure HTML sanitizationconst sanitized = DOMPurify.sanitize(contentString, SANITIZE_CONFIG);element.innerHTML = sanitized;@@ -195,7 +198,7 @@ function createSafeAlertElement(message, type = 'info') {function sanitizeHtml(dirty, config = {}) {if (!dirty) return '';- if (hasDOMPurify) {+ if (hasDOMPurify()) {const finalConfig = { ...SANITIZE_CONFIG, ...config };return DOMPurify.sanitize(String(dirty), finalConfig);} else {diff --git a/tests/infrastructure_tests/test_xss_protection.test.js b/tests/infrastructure_tests/test_xss_protection.test.jsindex 90091df45c..67ab727f09 100644--- a/tests/infrastructure_tests/test_xss_protection.test.js+++ b/tests/infrastructure_tests/test_xss_protection.test.js@@ -271,3 +271,88 @@ describe('App.js DOMPurify Export', () => {expect(typeof global.window.DOMPurify.sanitize).toBe('function');});});++describe('DOMPurify KEEP_CONTENT Configuration', () => {+ test('should preserve text content when sanitizing highlighted dropdown items', () => {+ const { sanitizeHtml } = global.window;++ // Simulate a model name with highlighting like in dropdowns+ const modelWithHighlight = 'google/<span class="ldr-highlight">gemma</span>-3n-e2b-it:free (OPENROUTER)';+ const result = sanitizeHtml(modelWithHighlight);++ // Verify DOMPurify was called with KEEP_CONTENT: true+ // This ensures text content is preserved even if tags are processed+ expect(mockDOMPurify.sanitize).toHaveBeenCalledWith(+ modelWithHighlight,+ expect.objectContaining({+ KEEP_CONTENT: true+ })+ );+ });++ test('sanitized output should contain original text content', () => {+ // The mock preserves content, simulating KEEP_CONTENT: true behavior+ const input = 'google/<span class="ldr-highlight">gemma</span>-3n-e2b-it:free';+ const result = mockDOMPurify.sanitize(input, {});++ // Text content should be preserved, not empty+ expect(result).toContain('google/');+ expect(result).toContain('gemma');+ expect(result).toContain('-3n-e2b-it:free');+ });++ test('should handle complex model names with special characters', () => {+ const { sanitizeHtml } = global.window;++ // Test various model name formats that appear in dropdowns+ const testCases = [+ 'meta-llama/llama-3.3-70b-instruct:free',+ 'anthropic/claude-3.5-sonnet:beta',+ 'openai/gpt-4o-2024-11-20',+ 'bytedance-seed/seed-1.6-flash-h'+ ];++ testCases.forEach(modelName => {+ const highlighted = modelName.replace(/(llama|claude|gpt|seed)/gi,+ '<span class="ldr-highlight">$1</span>');+ const result = sanitizeHtml(highlighted);++ // Should call sanitize and preserve content+ expect(mockDOMPurify.sanitize).toHaveBeenCalled();+ });+ });+});++describe('Dynamic DOMPurify Detection', () => {+ test('safeSetInnerHTML should check for DOMPurify availability at call time', () => {+ const { safeSetInnerHTML } = global.window;+ const element = { innerHTML: '', textContent: '' };++ // Clear previous calls+ mockDOMPurify.sanitize.mockClear();++ // Call safeSetInnerHTML with HTML content+ safeSetInnerHTML(element, '<span class="ldr-highlight">test</span>', true);++ // DOMPurify should be used since it's available+ expect(mockDOMPurify.sanitize).toHaveBeenCalled();+ });++ test('safeSetInnerHTML should work even if DOMPurify loaded after script init', () => {+ // This test verifies the dynamic check behavior+ // In production, Vite modules load after regular scripts+ // The hasDOMPurify() function checks availability at call time, not load time++ const { safeSetInnerHTML } = global.window;+ const element = { innerHTML: '', textContent: '' };++ // Simulate calling after DOMPurify is available+ expect(global.DOMPurify).toBeDefined();++ safeSetInnerHTML(element, '<b>test</b>', true);++ // Should use DOMPurify, not fall back to textContent+ expect(mockDOMPurify.sanitize).toHaveBeenCalled();+ expect(element.innerHTML).toBeTruthy();+ });+});