Heuristic:ARCANGEL0 EVA Search Query Sanitization
| Knowledge Sources | |
|---|---|
| Domains | Security, Safety |
| Last Updated | 2026-10-29 12:00 GMT |
Overview
Sanitize vulnerability search queries by rejecting IP addresses, option-like strings, and inputs exceeding 220 characters to prevent search injection and irrelevant results.
Description
Mitsu's vulnerability search pipeline sanitizes all search queries through `_query_text`, which performs three checks: (1) the query must match a safe character pattern (`[A-Za-z0-9][A-Za-z0-9 ._:/+#-]{0,219}`), (2) the query must not be a valid IP address (rejected via `ipaddress.ip_address`), and (3) the query must not exceed 220 characters. Additionally, queries that are not product records must contain either a CVE pattern (`CVE-\d{4}-\d{3,}`) or a version clue (`product vX.Y.Z`) to be included. This prevents injecting search-engine operators, URLs, or nonsensical queries into web search engines.
Usage
Apply this heuristic to all vulnerability search queries generated from session Intel or user-provided criteria. The sanitization runs automatically in `vulnerability_queries` and `search_vulnerabilities`.
The Insight (Rule of Thumb)
- Action: Validate all search queries with `_query_text` before sending to search engines.
- Value: Max 220 chars, safe character set, no raw IPs, CVE or version clue required for non-product queries.
- Trade-off: Some valid but unusual search terms may be rejected, but prevents search injection and wasted API calls.
- Compatibility: Applies to all search engines (web, Exploit-DB, Vulnx).
Reasoning
Search engine queries constructed from untrusted Intel data could contain injection payloads, command-line options that search engines interpret specially, or IP addresses that produce irrelevant results. By enforcing a strict character set, length limit, and IP rejection, Mitsu ensures only product/version/CVE-style queries reach external search engines. The CVE-or-version-clue requirement for non-product queries ensures only actionable vulnerability searches are performed, not random string searches.
Code Evidence
Query sanitization from `search/vulnerabilities.py:16-32`:
_QUERY_CHARS = re.compile(r"[A-Za-z0-9][A-Za-z0-9 ._:/+#-]{0,219}\Z")
_CVE = re.compile(r"\bCVE-\d{4}-\d{3,}\b", re.IGNORECASE)
_VERSION_CLUE = re.compile(r"\b[A-Za-z][A-Za-z0-9_.+-]*\s+v?\d+(?:\.\d+){0,3}\b")
def _query_text(value: Any) -> str:
if not isinstance(value, str):
return ""
value = " ".join(value.split()).strip(" .,:;/")
if len(value) > 220 or not _QUERY_CHARS.fullmatch(value):
return ""
try:
ipaddress.ip_address(value)
return ""
except ValueError:
return value
Query generation from `search/vulnerabilities.py:41-48`:
def add(value: Any, product_record: bool = False) -> None:
query = _query_text(value)
if not query or (not product_record and not _CVE.search(query) and not _VERSION_CLUE.search(query)):
return
key = query.casefold()
if key not in seen and len(queries) < max(1, min(limit, 4)):
seen.add(key)
queries.append(query)
Criteria validation from `search/vulnerabilities.py:222-223`:
if criteria.strip() and not _query_text(criteria):
return "Use product, version, CVE, or vulnerability terms up to 220 characters."