~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
chore(lint): add eslint-plugin-regexp + fix 9 regex issues (incl 3 ReDoS) (#3662)
LearningCircuit0e9f86051adf
diff --git a/eslint.config.js b/eslint.config.jsindex 3fa0d4690c..5d17530f85 100644--- a/eslint.config.js+++ b/eslint.config.js@@ -3,6 +3,7 @@import nounsanitized from "eslint-plugin-no-unsanitized";import chaiFriendly from "eslint-plugin-chai-friendly";+import regexp from "eslint-plugin-regexp";// Recognized safe escape/sanitize methods for no-unsanitized plugin.// Implementations:@@ -37,6 +38,10 @@ export default ["**/*.min.js",],},+ // Catch regex anti-patterns and ReDoS hazards. Recommended preset only —+ // ~67 rules, all the safety-relevant ones already in the project's verified+ // zero/near-zero violation profile.+ regexp.configs["flat/recommended"],{// Apply to all JavaScript filesfiles: ["**/*.js", "**/*.mjs"],diff --git a/package-lock.json b/package-lock.jsonindex d21ae2adb2..ff5eeac9fb 100644--- a/package-lock.json+++ b/package-lock.json@@ -27,6 +27,7 @@"eslint": "^10.2.1","eslint-plugin-chai-friendly": "^1.2.0","eslint-plugin-no-unsanitized": "^4.1.5",+ "eslint-plugin-regexp": "^3.1.0","happy-dom": "^20.9.0","vite": "^7.3.2","vitest": "^4.1.2"@@ -1542,6 +1543,16 @@"chart.js": ">=4.0.0"}},+ "node_modules/comment-parser": {+ "version": "1.4.6",+ "resolved": "https://registry.npmjs.org/comment-parser/-/comment-parser-1.4.6.tgz",+ "integrity": "sha512-ObxuY6vnbWTN6Od72xfwN9DbzC7Y2vv8u1Soi9ahRKL37gb6y1qk6/dgjs+3JWuXJHWvsg3BXIwzd/rkmAwavg==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">= 12.0.0"+ }+ },"node_modules/convert-source-map": {"version": "2.0.0","resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz",@@ -1804,6 +1815,28 @@"eslint": "^9 || ^10"}},+ "node_modules/eslint-plugin-regexp": {+ "version": "3.1.0",+ "resolved": "https://registry.npmjs.org/eslint-plugin-regexp/-/eslint-plugin-regexp-3.1.0.tgz",+ "integrity": "sha512-qGXIC3DIKZHcK1H9A9+Byz9gmndY6TTSRkSMTZpNXdyCw2ObSehRgccJv35n9AdUakEjQp5VFNLas6BMXizCZg==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@eslint-community/eslint-utils": "^4.2.0",+ "@eslint-community/regexpp": "^4.11.0",+ "comment-parser": "^1.4.0",+ "jsdoc-type-pratt-parser": "^7.0.0",+ "refa": "^0.12.1",+ "regexp-ast-analysis": "^0.7.1",+ "scslre": "^0.3.0"+ },+ "engines": {+ "node": "^20.19.0 || ^22.13.0 || >=24"+ },+ "peerDependencies": {+ "eslint": ">=9.38.0"+ }+ },"node_modules/eslint-scope": {"version": "9.1.2","resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-9.1.2.tgz",@@ -2214,6 +2247,16 @@"dev": true,"license": "MIT"},+ "node_modules/jsdoc-type-pratt-parser": {+ "version": "7.2.0",+ "resolved": "https://registry.npmjs.org/jsdoc-type-pratt-parser/-/jsdoc-type-pratt-parser-7.2.0.tgz",+ "integrity": "sha512-dh140MMgjyg3JhJZY/+iEzW+NO5xR2gpbDFKHqotCmexElVntw7GjWjt511+C/Ef02RU5TKYrJo/Xlzk+OLaTw==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=20.0.0"+ }+ },"node_modules/json-buffer": {"version": "3.0.1","resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz",@@ -2570,6 +2613,19 @@"performance-now": "^2.1.0"}},+ "node_modules/refa": {+ "version": "0.12.1",+ "resolved": "https://registry.npmjs.org/refa/-/refa-0.12.1.tgz",+ "integrity": "sha512-J8rn6v4DBb2nnFqkqwy6/NnTYMcgLA+sLr0iIO41qpv0n+ngb7ksag2tMRl0inb1bbO/esUwzW1vbJi7K0sI0g==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@eslint-community/regexpp": "^4.8.0"+ },+ "engines": {+ "node": "^12.0.0 || ^14.0.0 || >=16.0.0"+ }+ },"node_modules/regenerator-runtime": {"version": "0.13.11","resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz",@@ -2577,6 +2633,20 @@"license": "MIT","optional": true},+ "node_modules/regexp-ast-analysis": {+ "version": "0.7.1",+ "resolved": "https://registry.npmjs.org/regexp-ast-analysis/-/regexp-ast-analysis-0.7.1.tgz",+ "integrity": "sha512-sZuz1dYW/ZsfG17WSAG7eS85r5a0dDsvg+7BiiYR5o6lKCAtUrEwdmRmaGF6rwVj3LcmAeYkOWKEPlbPzN3Y3A==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@eslint-community/regexpp": "^4.8.0",+ "refa": "^0.12.1"+ },+ "engines": {+ "node": "^12.0.0 || ^14.0.0 || >=16.0.0"+ }+ },"node_modules/rgbcolor": {"version": "1.0.1","resolved": "https://registry.npmjs.org/rgbcolor/-/rgbcolor-1.0.1.tgz",@@ -2632,6 +2702,21 @@"fsevents": "~2.3.2"}},+ "node_modules/scslre": {+ "version": "0.3.0",+ "resolved": "https://registry.npmjs.org/scslre/-/scslre-0.3.0.tgz",+ "integrity": "sha512-3A6sD0WYP7+QrjbfNA2FN3FsOaGGFoekCVgTyypy53gPxhbkCIjtO6YWgdrfM+n/8sI8JeXZOIxsHjMTNxQ4nQ==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@eslint-community/regexpp": "^4.8.0",+ "refa": "^0.12.0",+ "regexp-ast-analysis": "^0.7.0"+ },+ "engines": {+ "node": "^14.0.0 || >=16.0.0"+ }+ },"node_modules/semver": {"version": "7.7.4","resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz",diff --git a/package.json b/package.jsonindex decb8fb7b3..240b793976 100644--- a/package.json+++ b/package.json@@ -39,6 +39,7 @@"eslint": "^10.2.1","eslint-plugin-chai-friendly": "^1.2.0","eslint-plugin-no-unsanitized": "^4.1.5",+ "eslint-plugin-regexp": "^3.1.0","happy-dom": "^20.9.0","vite": "^7.3.2","vitest": "^4.1.2"diff --git a/src/local_deep_research/web/static/js/components/results.js b/src/local_deep_research/web/static/js/components/results.jsindex 0c6c563480..771b9144b7 100644--- a/src/local_deep_research/web/static/js/components/results.js+++ b/src/local_deep_research/web/static/js/components/results.js@@ -373,8 +373,11 @@queryElement.textContent = extractedQuery;}} else {- // Try to find the second heading if first was "Table of Contents"- const secondHeadingMatch = data.content.match(/^#\s*([^\n]+)[\s\S]*?^##\s*([^\n]+)/m);+ // Try to find the second heading if first was "Table of Contents".+ // The captured heading text starts with a non-whitespace char (\S)+ // to avoid backtracking ambiguity with the preceding [ \t]++ // (regexp/no-super-linear-backtracking).+ const secondHeadingMatch = data.content.match(/^#[ \t]+(\S[^\n]*)\n[\s\S]*?^##[ \t]+(\S[^\n]*)/m);if (secondHeadingMatch && secondHeadingMatch[2]) {const queryElement = document.getElementById('result-query');if (queryElement) {diff --git a/src/local_deep_research/web/static/js/mobile-navigation.js b/src/local_deep_research/web/static/js/mobile-navigation.jsindex 245027e94b..6c324a672d 100644--- a/src/local_deep_research/web/static/js/mobile-navigation.js+++ b/src/local_deep_research/web/static/js/mobile-navigation.js@@ -572,7 +572,7 @@const userInfo = document.querySelector('.ldr-user-info');if (userInfo) {const text = userInfo.textContent || '';- return text.trim().replace(/[^\w\s@._-]/g, '').trim() || 'User';+ return text.trim().replace(/[^\w\[email protected]]/g, '').trim() || 'User';}return 'User';}diff --git a/src/local_deep_research/web/static/js/pages/subscriptions.js b/src/local_deep_research/web/static/js/pages/subscriptions.jsindex 45efed67cd..e01714977e 100644--- a/src/local_deep_research/web/static/js/pages/subscriptions.js+++ b/src/local_deep_research/web/static/js/pages/subscriptions.js@@ -335,7 +335,7 @@ async function runSubscriptionNow(subscriptionId) {if ((data.status === 'success' || data.status === window.RESEARCH_STATUS.QUEUED) && data.research_id) {// Validate research_id is a safe UUID format before using in URL- const safeResearchId = String(data.research_id).replace(/[^a-zA-Z0-9-]/g, '');+ const safeResearchId = String(data.research_id).replace(/[^a-z0-9-]/gi, '');showAlert(`Research started! <a href="/progress/${safeResearchId}" style="color: white; text-decoration: underline;">View progress</a>`, 'success');// Store active research in localStorage so news page can show progress@@ -457,7 +457,7 @@ function showSubscriptionHistoryModal(subscription, historyData) {// Escape user-controlled valuesconst safeHeadline = escapeHtml(item.headline || '[No headline]');// Sanitize status to alphanumeric for safe CSS class usage- const safeStatusClass = (item.status || 'unknown').replace(/[^a-zA-Z0-9_-]/g, '');+ const safeStatusClass = (item.status || 'unknown').replace(/[^\w-]/g, '');const safeStatus = escapeHtml(item.status || 'unknown');return `<div class="ldr-history-item">diff --git a/src/local_deep_research/web/static/js/security/url-validator.js b/src/local_deep_research/web/static/js/security/url-validator.jsindex 90e1618e2a..2d87934f52 100644--- a/src/local_deep_research/web/static/js/security/url-validator.js+++ b/src/local_deep_research/web/static/js/security/url-validator.js@@ -94,7 +94,7 @@ const URLValidator = {url = url.trim();// Add scheme if missing- if (!url.match(/^[a-zA-Z][a-zA-Z\d+\-.]*:/)) {+ if (!url.match(/^[a-z][a-z\d+\-.]*:/i)) {url = `${defaultScheme}://${url}`;}diff --git a/src/local_deep_research/web/static/js/services/formatting.js b/src/local_deep_research/web/static/js/services/formatting.jsindex 6bfa2a328e..e5bbc9ffc5 100644--- a/src/local_deep_research/web/static/js/services/formatting.js+++ b/src/local_deep_research/web/static/js/services/formatting.js@@ -98,7 +98,7 @@ function capitalizeFirstLetter(string) {*/function formatNumber(num) {if (num === null || num === undefined) return '0';- return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");+ return num.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");}/**diff --git a/tests/infrastructure_tests/test_urls.test.js b/tests/infrastructure_tests/test_urls.test.jsindex 4850dc8c62..65360b33c7 100644--- a/tests/infrastructure_tests/test_urls.test.js+++ b/tests/infrastructure_tests/test_urls.test.js@@ -180,7 +180,7 @@ describe('URLs Configuration', () => {// Check that placeholders use {name} formatconst placeholders = value.match(/\{[^}]+\}/g) || [];placeholders.forEach(placeholder => {- expect(placeholder).toMatch(/^\{[a-zA-Z_]+\}$/);+ expect(placeholder).toMatch(/^\{[a-z_]+\}$/i);});} else if (typeof value === 'object' && value !== null) {checkPlaceholders(value);diff --git a/tests/ui_tests/test_benchmark_ci.js b/tests/ui_tests/test_benchmark_ci.jsindex 7f60749e93..b78734459e 100644--- a/tests/ui_tests/test_benchmark_ci.js+++ b/tests/ui_tests/test_benchmark_ci.js@@ -287,7 +287,7 @@ const BenchmarkResultsTests = {);// Look for percentage or score pattern- const scorePattern = /(\d+\.?\d*)\s*(%|\/\s*100|points?|score)/i;+ const scorePattern = /(\d+(?:\.\d*)?)\s*(?:%|\/\s*100|points?|score)/i;const bodyText = document.body.textContent || '';const scoreMatch = bodyText.match(scorePattern);diff --git a/tests/ui_tests/test_context_overflow_ci.js b/tests/ui_tests/test_context_overflow_ci.jsindex 051fd792fc..81b2575649 100644--- a/tests/ui_tests/test_context_overflow_ci.js+++ b/tests/ui_tests/test_context_overflow_ci.js@@ -52,7 +52,7 @@ const ContextOverflowTests = {);// Look for percentage pattern- const percentPattern = /(\d+\.?\d*)\s*%/;+ const percentPattern = /(\d+(?:\.\d*)?)\s*%/;const bodyText = document.body.textContent || '';const percentMatch = bodyText.match(percentPattern);@@ -92,7 +92,7 @@ const ContextOverflowTests = {);// Look for token count patterns- const tokenPattern = /(\d+[\d,]*)\s*(tokens?|truncated)/i;+ const tokenPattern = /(\d[\d,]*)\s*(?:tokens?|truncated)/i;const bodyText = document.body.textContent || '';const tokenMatch = bodyText.match(tokenPattern);diff --git a/tests/ui_tests/test_lib/test_results.js b/tests/ui_tests/test_lib/test_results.jsindex d9535eec54..a31f190b38 100644--- a/tests/ui_tests/test_lib/test_results.js+++ b/tests/ui_tests/test_lib/test_results.js@@ -112,7 +112,7 @@ class TestResults {if (!fs.existsSync(screenshotDir)) {fs.mkdirSync(screenshotDir, { recursive: true });}- const safeName = `${category}_${name}`.replace(/[^a-zA-Z0-9]/g, '_');+ const safeName = `${category}_${name}`.replace(/[^a-z0-9]/gi, '_');const screenshotPath = path.join(screenshotDir, `failure_${safeName}_${Date.now()}.png`);await context.page.screenshot({ path: screenshotPath, fullPage: true });console.log(` \x1b[90mScreenshot saved: ${screenshotPath}\x1b[0m`);@@ -235,7 +235,7 @@ class TestResults {fs.mkdirSync(outputDir, { recursive: true });}- const safeName = this.suiteName.replace(/[^a-zA-Z0-9]/g, '-').toLowerCase();+ const safeName = this.suiteName.replace(/[^a-z0-9]/gi, '-').toLowerCase();if (options.json !== false) {const jsonPath = path.join(outputDir, `${safeName}.json`);diff --git a/tests/ui_tests/test_library_documents_ci.js b/tests/ui_tests/test_library_documents_ci.jsindex 87bdd00a47..c21811ac5e 100644--- a/tests/ui_tests/test_library_documents_ci.js+++ b/tests/ui_tests/test_library_documents_ci.js@@ -48,7 +48,7 @@ const LibraryPageTests = {// Look for any numbers that might be statsconst pageText = document.body.textContent;- const hasNumbers = /\d+\s*(PDFs?|documents?|MB|GB|files?)/i.test(pageText);+ const hasNumbers = /\d+\s*(?:PDFs?|documents?|MB|GB|files?)/i.test(pageText);return {hasStatsArea: !!statsArea,diff --git a/tests/ui_tests/test_metrics_dashboard_ci.js b/tests/ui_tests/test_metrics_dashboard_ci.jsindex 12862f5773..0392491a87 100644--- a/tests/ui_tests/test_metrics_dashboard_ci.js+++ b/tests/ui_tests/test_metrics_dashboard_ci.js@@ -443,7 +443,7 @@ const StarReviewsTests = {);// Look for a number that could be an average (e.g., 4.2, 3.5)- const avgPattern = /(\d+\.?\d*)\s*(\/\s*5|stars?|out of)/i;+ const avgPattern = /(\d+(?:\.\d*)?)\s*(?:\/\s*5|stars?|out of)/i;const bodyText = document.body.textContent || '';const avgMatch = bodyText.match(avgPattern);diff --git a/tests/ui_tests/test_realtime_progress_ci.js b/tests/ui_tests/test_realtime_progress_ci.jsindex 95fcad6381..6d2ef91c86 100644--- a/tests/ui_tests/test_realtime_progress_ci.js+++ b/tests/ui_tests/test_realtime_progress_ci.js@@ -349,7 +349,7 @@ const ProgressPageTests = {);// Look for phase/step text patterns- const phasePattern = /(phase|step|stage)\s*[:\d]/i;+ const phasePattern = /(?:phase|step|stage)\s*[:\d]/i;const bodyText = document.body.textContent || '';const hasPhaseText = phasePattern.test(bodyText);@@ -401,7 +401,7 @@ const ProgressPageTests = {);// Look for time patterns- const timePattern = /(\d+\s*(min|sec|hour|s|m|h)|remaining|elapsed|eta)/i;+ const timePattern = /\d+\s*(?:min|sec|hour|[smh])|remaining|elapsed|eta/i;const bodyText = document.body.textContent || '';const hasTimeText = timePattern.test(bodyText);diff --git a/tests/ui_tests/test_research_diagnosis.js b/tests/ui_tests/test_research_diagnosis.jsindex 79fb9e5ab4..f4b62c52a4 100644--- a/tests/ui_tests/test_research_diagnosis.js+++ b/tests/ui_tests/test_research_diagnosis.js@@ -131,7 +131,7 @@ async function testResearchDiagnosis() {.map(s => s.textContent).join('\n');- const apiMatches = scriptContent.match(/['"](\/api\/[^'"]+)['"]/g) || [];+ const apiMatches = scriptContent.match(/['"]\/api\/[^'"]+['"]/g) || [];info.apiEndpoints = [...new Set(apiMatches.map(m => m.slice(1, -1)))];return info;diff --git a/vite.config.js b/vite.config.jsindex 6df7a9d287..0695fca9ec 100644--- a/vite.config.js+++ b/vite.config.js@@ -29,7 +29,7 @@ export default defineConfig({if (assetInfo.name.endsWith('.css')) {return 'css/[name].[hash][extname]';}- if (/\.(woff2?|ttf|eot|svg)$/.test(assetInfo.name)) {+ if (/\.(?:woff2?|ttf|eot|svg)$/.test(assetInfo.name)) {return 'fonts/[name].[hash][extname]';}return 'assets/[name].[hash][extname]';