Skip to content

~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.

fix: add tabnabbing protection and settings.js XSS fallback

LearningCircuit64e28739f1c8
diff --git a/src/local_deep_research/web/static/js/components/settings.js b/src/local_deep_research/web/static/js/components/settings.js
index b4dc3ccd78..9961e3fa96 100644
--- a/src/local_deep_research/web/static/js/components/settings.js
+++ b/src/local_deep_research/web/static/js/components/settings.js
@@ -1545,11 +1545,16 @@
</div>
`;
} 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) => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'})[m]);
+ const safeDataDirCompact = (window.escapeHtml || escapeHtmlFallback)(data.data_directory);
+
html += `
<div class="data-location-compact">
<div class="data-path">
<i class="fas fa-folder"></i>
- <code>${data.data_directory}</code>
+ <code>${safeDataDirCompact}</code>
</div>
<div class="security-status unencrypted">
<i class="fas fa-exclamation-triangle"></i>
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.js
index 60232739da..dd3f967a50 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
@@ -28,6 +28,7 @@
* Files using this pattern:
* - components/results.js
* - components/fallback/ui.js
+ * - components/settings.js
* - services/ui.js
*/
@@ -40,6 +41,18 @@
return typeof DOMPurify !== 'undefined';
}
+ // Configure DOMPurify hooks to prevent tabnabbing attacks
+ // This must be done at module load time, before any sanitization occurs
+ if (hasDOMPurify()) {
+ DOMPurify.addHook('afterSanitizeAttributes', function(node) {
+ // Enforce rel="noopener noreferrer" on all links with target="_blank"
+ // This prevents the opened page from accessing window.opener
+ if (node.tagName === 'A' && node.getAttribute('target') === '_blank') {
+ node.setAttribute('rel', 'noopener noreferrer');
+ }
+ });
+ }
+
/**
* HTML entity encoding map for XSS prevention
*/
@@ -57,7 +70,7 @@
*/
const SANITIZE_CONFIG = {
ALLOWED_TAGS: ['b', 'i', 'em', 'strong', 'span', 'br', 'p', 'div', 'ul', 'ol', 'li', 'a', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'],
- ALLOWED_ATTR: ['class', 'id', 'href', 'title', 'alt', 'target'],
+ ALLOWED_ATTR: ['class', 'id', 'href', 'title', 'alt', 'target', 'rel'],
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*'],
diff --git a/tests/infrastructure_tests/test_xss_protection.test.js b/tests/infrastructure_tests/test_xss_protection.test.js
index 67ab727f09..7d62812380 100644
--- a/tests/infrastructure_tests/test_xss_protection.test.js
+++ b/tests/infrastructure_tests/test_xss_protection.test.js
@@ -16,7 +16,15 @@ const mockDOMPurify = {
result = result.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '');
// Keep allowed tags like span with class
return result;
- })
+ }),
+ addHook: jest.fn((hookName, callback) => {
+ // Mock addHook for tabnabbing protection
+ // Stores callbacks but doesn't execute them in tests
+ mockDOMPurify._hooks = mockDOMPurify._hooks || {};
+ mockDOMPurify._hooks[hookName] = mockDOMPurify._hooks[hookName] || [];
+ mockDOMPurify._hooks[hookName].push(callback);
+ }),
+ _hooks: {}
};
// Setup global mocks