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(security): handle null/undefined in escapeHtml function (#1858)

LearningCircuit31a5b8e60af1
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 cf42dbb22d..91bf35b186 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
@@ -103,12 +103,15 @@
* @returns {string} - The escaped text safe for HTML content
*/
function escapeHtml(text) {
- if (typeof text !== 'string') {
- text = String(text);
- }
+ if (text === null || text === undefined) {
+ return '';
+ }
+ if (typeof text !== 'string') {
+ text = String(text);
+ }
- return text.replace(/[&<>"'/]/g, (match) => HTML_ESCAPE_MAP[match]);
-}
+ return text.replace(/[&<>"'/]/g, (match) => HTML_ESCAPE_MAP[match]);
+ }
/**
* Escape HTML attributes to prevent XSS
diff --git a/tests/infrastructure_tests/test_xss_protection.test.js b/tests/infrastructure_tests/test_xss_protection.test.js
index 7d62812380..929b8ce372 100644
--- a/tests/infrastructure_tests/test_xss_protection.test.js
+++ b/tests/infrastructure_tests/test_xss_protection.test.js
@@ -78,7 +78,8 @@ describe('XSS Protection Module', () => {
test('should handle non-string input', () => {
const { escapeHtml } = global.window;
expect(escapeHtml(123)).toBe('123');
- expect(escapeHtml(null)).toBe('null');
+ expect(escapeHtml(null)).toBe('');
+ expect(escapeHtml(undefined)).toBe('');
});
});