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.

security: fix XSS vulnerabilities in collection_upload.js

LearningCircuitbb7a15b5ede1
diff --git a/src/local_deep_research/web/static/js/collection_upload.js b/src/local_deep_research/web/static/js/collection_upload.js
index 6ac8f183d4..6862850d10 100644
--- a/src/local_deep_research/web/static/js/collection_upload.js
+++ b/src/local_deep_research/web/static/js/collection_upload.js
@@ -17,6 +17,17 @@ async function safeFetch(url, options = {}) {
return fetch(url, options);
}
+/**
+ * Escape HTML special characters to prevent XSS attacks
+ * @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;
+}
+
// Store selected files globally to avoid losing them
let selectedFiles = [];
@@ -139,7 +150,7 @@ function showSelectedFiles(files) {
const fileSize = (file.size / 1024 / 1024).toFixed(2) + ' MB';
li.innerHTML = `
<i class="fas fa-file"></i>
- <span>${file.name} (${fileSize})</span>
+ <span>${escapeHtml(file.name)} (${fileSize})</span>
`;
fileList.appendChild(li);
});
@@ -298,7 +309,7 @@ function showCleanProgress(files) {
<div id="file-${index}" style="display: flex; align-items: center; padding: 0.75rem; background: white; border-radius: 6px; margin-bottom: 0.5rem; border: 1px solid #dee2e6;">
<i class="fas fa-spinner fa-spin" style="color: #667eea; margin-right: 0.75rem; width: 16px;"></i>
<div style="flex: 1;">
- <div style="font-weight: 500; color: #333; margin-bottom: 0.25rem;">${file.name}</div>
+ <div style="font-weight: 500; color: #333; margin-bottom: 0.25rem;">${escapeHtml(file.name)}</div>
<div style="font-size: 0.85rem; color: #6c757d;">${fileSize} MB</div>
</div>
<span style="font-size: 0.85rem; color: #667eea; font-weight: 500;">Uploading...</span>
@@ -383,7 +394,7 @@ function showUploadResults(data) {
if (data.uploaded_files && data.uploaded_files.length > 0) {
html += '<p><strong>Successfully uploaded:</strong></p><ul>';
data.uploaded_files.forEach(file => {
- html += `<li>✅ ${file.name} (${(file.size / 1024 / 1024).toFixed(2)} MB)</li>`;
+ html += `<li>✅ ${escapeHtml(file.name)} (${(file.size / 1024 / 1024).toFixed(2)} MB)</li>`;
});
html += '</ul>';
}
@@ -391,7 +402,7 @@ function showUploadResults(data) {
if (data.failed_files && data.failed_files.length > 0) {
html += '<p><strong>Failed to upload:</strong></p><ul>';
data.failed_files.forEach(file => {
- html += `<li>❌ ${file.name}: ${file.error}</li>`;
+ html += `<li>❌ ${escapeHtml(file.name)}: ${escapeHtml(file.error)}</li>`;
});
html += '</ul>';
}