T09 · Insecure Skill Coding Practices
- Location
scripts/searxng.py:72- Finding
Unvalidated SearXNG Endpoint Can Disclose Search Queries to an Unintended Service
- Content
View full analysis
Vulnerability Details
File Location:
scripts/searxng.py, lines 72-74, 101-117, and 168-171
Vulnerability Type: Unvalidated service endpoint and unsafe service discovery
Risk Level: MediumVulnerable Code
python env_url = os.getenv("SEARXNG_URL") if env_url: return env_url.rstrip('/')python common_ports = [8080, 8888, 9000, 8000] for port in common_ports: try: import socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(1) result = sock.connect_ex(("localhost", port)) sock.close() if result == 0: url = f"http://localhost:{port}" print(f"Found service at port {port}, assuming SearXNG: {url}", file=sys.stderr) return url except Exception: passpython params = {'q': query, 'format': 'json'} url = f"{self.base_url}/search" try: async with session.get(url, params=params) as response:Technical Analysis
The
SEARXNG_URLenvironment variable is accepted without validating its scheme, host, port, credentials, or path. Automatic discovery also assumes that any process listening on one of several common localhost ports is a SearXNG instance. No application-level request is performed to verify the identity of the selected service before user queries are transmitted.The selected endpoint receives the query through an HTTP GET request. Plain HTTP is permitted, and
aiohttpfollows redirects by default. Consequently, a malicious or incorrectly identified service can receive potentially sensitive search terms. If an attacker can influence the environment variable or operate a process on a probed port, the attacker can control where requests are sent.Attack Path
- An attacker influences
SEARXNG_URL, controls a service on one of the automatically probed localhost ports, or controls a selected endpoint that retu ...[truncated 839 chars]
- An attacker influences
- Remediation
View remediation
Remediation Suggestions
- Parse endpoints with
urllib.parse.urlsplitand allow only explicitly supportedhttpandhttpsschemes. - Reject embedded credentials, malformed hosts, unexpected paths, and unsupported URL schemes.
- Require HTTPS for non-loopback endpoints. If local plain HTTP is necessary, restrict it to validated loopback addresses.
- Apply an explicit allowlist of approved hosts or network ranges where deployment requirements permit it.
- Verify discovered services through a SearXNG-specific API request and expected response structure rather than relying only on an open TCP port.
- Disable redirects with
allow_redirects=False, or validate every redirect target before following it. - Avoid silently selecting an arbitrary service on a common port. Require explicit confirmation or fail closed when service identity cannot be established.
- Document the trust requirements for
SEARXNG_URLand ensure untrusted callers cannot modify the process environment.
- Parse endpoints with
