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: replace regex with string operations to avoid ReDoS

LearningCircuita808049defa5
diff --git a/src/local_deep_research/web_search_engines/search_engine_factory.py b/src/local_deep_research/web_search_engines/search_engine_factory.py
index 9a4b549970..534cf16028 100644
--- a/src/local_deep_research/web_search_engines/search_engine_factory.py
+++ b/src/local_deep_research/web_search_engines/search_engine_factory.py
@@ -89,28 +89,34 @@ def create_search_engine(
# e.g., "🔬 OpenAlex (Scientific)"
# Try to extract the base name from the label
- # Use a safe regex pattern to avoid ReDoS vulnerabilities
- import re
-
- # Pattern: non-space chars (icon), space, captured group (base name - no parens),
- # space, open paren, text, close paren
- label_match = re.match(r"^[^\s]+\s+([^()]+)\s+\([^)]+\)$", engine_name)
- if label_match:
- base_name = label_match.group(1).strip()
- logger.info(
- f"Extracted base name '{base_name}' from label '{engine_name}'"
- )
+ # To avoid ReDoS, we use string operations instead of regex
+ # Pattern: icon, space, base_name, space, (category)
+ # Example: "🔬 OpenAlex (Scientific)"
+ if " (" in engine_name and engine_name.endswith(")"):
+ # Split on the last occurrence of ' ('
+ parts = engine_name.rsplit(" (", 1)
+ if len(parts) == 2:
+ # Remove icon (first word) from the beginning
+ before_paren = parts[0]
+ space_idx = before_paren.find(" ")
+ if space_idx > 0:
+ base_name = before_paren[space_idx + 1 :].strip()
+ logger.info(
+ f"Extracted base name '{base_name}' from label '{engine_name}'"
+ )
- # Search for a config entry with matching display_name
- for config_key, config_data in config.items():
- if isinstance(config_data, dict):
- display_name = config_data.get("display_name", config_key)
- if display_name == base_name:
- logger.info(
- f"Matched label to config key: '{engine_name}' -> '{config_key}'"
- )
- engine_name = config_key
- break
+ # Search for a config entry with matching display_name
+ for config_key, config_data in config.items():
+ if isinstance(config_data, dict):
+ display_name = config_data.get(
+ "display_name", config_key
+ )
+ if display_name == base_name:
+ logger.info(
+ f"Matched label to config key: '{engine_name}' -> '{config_key}'"
+ )
+ engine_name = config_key
+ break
# If still not found, use default
if engine_name not in config: