Skip to content

feat(web-search): add SearXNG as bundled web search provider plugin - #57317

Merged
vincentkoc merged 5 commits into
openclaw:mainfrom
cgdusek:claude/laughing-edison
Apr 1, 2026
Merged

vincentkoc merged 5 commits into
openclaw:mainfrom
cgdusek:claude/laughing-edison

Conversation

@cgdusek

@cgdusek cgdusek commented Mar 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds SearXNG as a bundled web search provider plugin at extensions/searxng/, following the exact extensions/duckduckgo/ pattern
  • Uses SearXNG's native JSON API (format=json) — no HTML scraping
  • Auto-detects via SEARXNG_BASE_URL env var; also configurable in openclaw.json plugin config
  • Auto-detect order 200 (lowest priority — any API-backed provider with a key wins)
  • Includes full test suite (unit tests + 3 contract tests), documentation, and docs.json registration

Closes #2317

Why

SearXNG is a self-hosted, open-source meta-search engine (aggregates Google, Bing, DuckDuckGo, etc.). It addresses three user pain points:

  • Cost: Brave Search charges for API access; SearXNG is free and unlimited
  • Privacy/air-gap: queries never leave your network, no API keys required
  • Availability: works in regions where commercial search APIs aren't accessible

This is the highest-reaction open issue (26 👍) without an acceptable PR. Eight prior PRs attempted this but none were merged — they either used the wrong architecture (inlining into monolithic web-search.ts) or shipped without tests.

Test plan

  • pnpm tsgo — TypeScript check passes
  • pnpm build — build passes (plugin auto-discovered)
  • pnpm check — lint + format passes
  • pnpm plugin-sdk:api:check — baseline regenerated and verified
  • pnpm test -- extensions/searxng/ — unit + contract tests (CI)
  • Manual: docker run -d -p 8888:8080 searxng/searxng + SEARXNG_BASE_URL=http://localhost:8888 openclaw configure --section web → select searxng → agent web_search returns results

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: telegram Channel integration: telegram gateway Gateway runtime agents Agent runtime and tooling extensions: acpx size: L labels Mar 29, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d39f101d64

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@greptile-apps

greptile-apps Bot commented Mar 29, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds SearXNG as a bundled web search provider plugin, following the existing DuckDuckGo extension pattern closely. The implementation is well-structured: it uses SearXNG's native JSON API (no HTML scraping), includes proper caching, content-wrapping security markers, full test coverage (unit + 3 contract tests), docs registration, and plugin config schema.

The vast majority of non-SearXNG file changes are trivial import reorderings and formatter-driven whitespace fixes with no logic impact.

Key concern:

  • The PR description and documentation state that SearXNG "auto-detects via SEARXNG_BASE_URL env var", but the runtime auto-detection logic (resolveWebSearchProviderId in src/web-search/runtime.ts) will never select SearXNG automatically. With requiresCredential: false and autoDetectOrder: 200, SearXNG is treated as a keyless fallback; DuckDuckGo (autoDetectOrder: 100, also keyless) is always picked first as the fallback provider. The envVars: [\"SEARXNG_BASE_URL\"] entry is only consulted by hasEntryCredential, which is never reached for keyless providers. Users who set only SEARXNG_BASE_URL will silently get DuckDuckGo results unless they also explicitly set tools.web.search.provider: \"searxng\".

Everything else looks good: the client, config resolution, test suite, and plugin metadata all follow established patterns correctly.

Confidence Score: 4/5

Safe to merge functionally — SearXNG works correctly when explicitly configured — but the auto-detection claim in docs and PR description does not match actual runtime behavior.

The core implementation is solid and the provider works correctly when selected explicitly. The P1 concern is a discrepancy between the documented 'auto-detects via SEARXNG_BASE_URL' behavior and the actual runtime logic, which will always prefer DuckDuckGo (autoDetectOrder 100) over SearXNG (200) as the keyless fallback. Users relying on the documented auto-detection behavior will be silently redirected to DuckDuckGo. This warrants attention before merge but is not a security or data-loss issue.

extensions/searxng/src/searxng-search-provider.ts — the autoDetectOrder and requiresCredential settings need to be reconciled with the auto-detection claim in the docs.

Important Files Changed

Filename Overview
extensions/searxng/src/searxng-search-provider.ts Provider registration follows the DuckDuckGo pattern correctly, but autoDetectOrder: 200 combined with requiresCredential: false means SearXNG can never be runtime-auto-detected over DuckDuckGo (order 100), conflicting with the documented auto-detection claim.
extensions/searxng/src/searxng-client.ts Client implementation is solid: JSON API endpoint, proper error handling, cache with normalization, content wrapping with wrapWebContent, and correct count slicing.
extensions/searxng/src/config.ts Config resolution functions are clean and well-tested. Plugin config takes precedence over env var with proper trimming and trailing-slash normalization.
extensions/searxng/src/searxng-search-provider.test.ts Comprehensive unit tests covering provider registration, credential metadata, argument mapping, base URL resolution, and autoDetectOrder.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: extensions/searxng/src/searxng-search-provider.ts
Line: 46

Comment:
**Auto-detection via `SEARXNG_BASE_URL` will not work as documented**

The PR description and docs claim SearXNG "auto-detects via `SEARXNG_BASE_URL` env var," but the runtime auto-detection logic in `src/web-search/runtime.ts` (`resolveWebSearchProviderId`) treats providers with `requiresCredential: false` as *keyless fallbacks* — it stores the first one it encounters (sorted by `autoDetectOrder`) and moves on. With DuckDuckGo at `autoDetectOrder: 100`, DDG is always stored as the keyless fallback before SearXNG (200) is reached. `SEARXNG_BASE_URL` is listed in `envVars`, but `hasEntryCredential` — the function that reads env vars — is never called for keyless providers (`requiresCredential: false`).

Concretely: a user who sets `SEARXNG_BASE_URL` without also explicitly setting `tools.web.search.provider: "searxng"` in `openclaw.json` will silently receive DuckDuckGo results, not SearXNG results.

For SearXNG to be auto-selected when `SEARXNG_BASE_URL` is present, one approach is to treat the base URL as a credential:

```ts
requiresCredential: true,
credentialPath: "plugins.entries.searxng.config.webSearch.baseUrl",
getCredentialValue: (searchConfig) =>
  getScopedCredentialValue(searchConfig, "searxng") ??
  process.env["SEARXNG_BASE_URL"],
```

Alternatively, if the intent is always to prefer explicit opt-in for SearXNG (which `autoDetectOrder: 200` implies), the docs and PR description should be corrected to remove the auto-detection claim so users know they must explicitly configure the provider.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "style: auto-format trailing comma and wh..." | Re-trigger Greptile

@cgdusek

cgdusek commented Mar 29, 2026

Copy link
Copy Markdown
Contributor Author

Addressed both review comments in db85698:

P1 (auto-detection): Switched to requiresCredential: true with credentialPath pointing to plugins.entries.searxng.config.webSearch.baseUrl and getCredentialValue falling back to process.env.SEARXNG_BASE_URL. Auto-detection now triggers correctly when the env var is set instead of silently falling back to DuckDuckGo.

P2 (path prefix): Replaced new URL("/search", baseUrl) with string concatenation (${normalizedBase}/search) that preserves any existing base path prefix (e.g. https://host/searxng → https://host/searxng/search).

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: db856987da

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cgdusek

cgdusek commented Mar 29, 2026

Copy link
Copy Markdown
Contributor Author

Addressed P1 from Codex review in fc64ead:

Store base URL in plugin config: Added getConfiguredCredentialValue/setConfiguredCredentialValue so openclaw configure --section web writes the base URL to plugins.entries.searxng.config.webSearch.baseUrl (where the SearXNG client actually reads it) instead of tools.web.search.searxng.apiKey. Added test coverage for the round-trip.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fc64ead02c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread extensions/searxng/openclaw.plugin.json Resolved
@cgdusek

cgdusek commented Mar 29, 2026

Copy link
Copy Markdown
Contributor Author

Addressed P2 from Codex review (SecretRef) in ff497a4:

Accept SecretRef objects for baseUrl: Changed configSchema.webSearch.baseUrl type from "string" to ["string", "object"], matching the Brave/Perplexity/etc. pattern. This ensures --secret-input-mode=ref works without schema validation rejecting the stored SecretRef object.


All 4 review comments now addressed:

  1. P1 (Greptile): Auto-detection won't work → Fixed: requiresCredential: true ✅
  2. P2 (Codex): Path prefix stripped → Fixed: string concatenation ✅
  3. P1 (Codex): Setup writes to wrong config path → Fixed: getConfiguredCredentialValue/setConfiguredCredentialValue ✅
  4. P2 (Codex): SecretRef rejected by schema → Fixed: type: ["string", "object"] ✅

@aisle-research-bot

aisle-research-bot Bot commented Mar 30, 2026 •

Copy link
Copy Markdown

🔒 Aisle Security Analysis

We found 2 potential security issue(s) in this PR:

# Severity Title
1 🟠 High SSRF via user-configurable SearXNG baseUrl fetched with private-network-allowed policy
2 🟡 Medium Unbounded JSON response parsing in SearXNG client can cause memory exhaustion (DoS)
Vulnerabilities

1. 🟠 SSRF via user-configurable SearXNG baseUrl fetched with private-network-allowed policy

Property Value
Severity High
CWE CWE-918
Location extensions/searxng/src/searxng-client.ts:80-110

Description

The SearXNG web search provider builds a request URL from a configurable baseUrl (from plugin credential/config or env) and fetches it using withTrustedWebSearchEndpoint.

  • baseUrl is user/operator configurable (credential path plugins.entries.searxng.config.webSearch.baseUrl) and is not restricted to public hosts.
  • withTrustedWebSearchEndpoint routes to withTrustedWebToolsEndpoint, which uses an SSRF policy with dangerouslyAllowPrivateNetwork: true.
  • As a result, a user who can set the SearXNG Base URL can make the server perform HTTP requests to internal resources (e.g. http://127.0.0.1/, http://10.0.0.0/8, cloud metadata IPs), and the response content can be surfaced back:
    • success path: parsed JSON results are returned
    • error path: up to 64KB of response body is included in the thrown error message

Vulnerable code:

const normalizedBase = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
const url = new URL(`${normalizedBase}/search`);
...
const results = await withTrustedWebSearchEndpoint({ url: url.toString(), ... }, ...);

And the trusted web tools guard explicitly allows private network targets:

const WEB_TOOLS_TRUSTED_NETWORK_SSRF_POLICY: SsrFPolicy = {
  dangerouslyAllowPrivateNetwork: true,
};

Recommendation

Treat baseUrl as untrusted input and prevent SSRF:

  1. Use a strict SSRF policy for user-configurable endpoints (disallow private/internal ranges), or introduce a dedicated helper like withUntrustedWebSearchEndpoint.
  2. Validate baseUrl on set/use:
    • require http(s)
    • reject localhost, .local, .internal
    • reject IP literals and private/link-local ranges
    • optionally enforce an allowlist of known SearXNG hosts
  3. Avoid reflecting response bodies from failed requests into errors returned to callers.

Example (conceptual):

import { withStrictWebToolsEndpoint } from ".../web-guarded-fetch";

​// Validate and parse
const parsed = new URL(baseUrl);
if (!['https:','http:'].includes(parsed.protocol)) throw new Error('Invalid baseUrl');
​// additionally block private IPs/hostnames here

return await withStrictWebToolsEndpoint(
  { url: new URL('/search', parsed).toString(), timeoutSeconds, init: { method: 'GET', headers: { Accept: 'application/json' } } },
  async ({ response }) => { /* ... */ }
);

If internal/private access is truly required, restrict who can set baseUrl (operator-only) and enforce an allowlist/pinning to that known instance.


2. 🟡 Unbounded JSON response parsing in SearXNG client can cause memory exhaustion (DoS)

Property Value
Severity Medium
CWE CWE-400
Location extensions/searxng/src/searxng-client.ts:105-115

Description

runSearxngSearch fetches JSON from the configured SearXNG instance and parses it with response.json() without any response-size limit.

  • Input/control: baseUrl is operator/config controlled, but the remote server (or a MITM if HTTP is used) fully controls the HTTP response body.
  • Sink: await response.json() will buffer and parse the entire body in memory.
  • Impact: A malicious/compromised SearXNG endpoint can return an extremely large JSON body, leading to high memory usage and potential process crash/availability loss.

Vulnerable code:

const body = (await response.json()) as SearxngResponse;

While error bodies are capped via readResponseText(..., { maxBytes: 64_000 }), successful responses are not capped.

Recommendation

Apply an explicit maximum size to successful responses before parsing JSON.

Options:

  1. Limit by Content-Length (best-effort, can be absent/incorrect):
const maxBytes = 1_000_000; // 1MB, tune as needed
const len = response.headers.get("content-length");
if (len && Number(len) > maxBytes) {
  throw new Error(`SearXNG response too large (${len} bytes)`);
}
  1. Enforce a hard cap by reading a bounded amount and JSON.parse (stronger):
const { text, truncated } = await readResponseText(response, { maxBytes: 1_000_000 });
if (truncated) throw new Error("SearXNG response too large");
const body = JSON.parse(text) as SearxngResponse;

Also consider documenting/requiring https:// base URLs where possible to reduce MITM risk.


Analyzed PR: #57317 at commit ff497a4

Last updated on: 2026-03-30T09:59:14Z

@vincentkoc
vincentkoc force-pushed the claude/laughing-edison branch from ff497a4 to 7eff513 Compare April 1, 2026 09:49
@openclaw-barnacle openclaw-barnacle Bot removed docs Improvements or additions to documentation channel: telegram Channel integration: telegram gateway Gateway runtime labels Apr 1, 2026
@openclaw-barnacle openclaw-barnacle Bot removed agents Agent runtime and tooling extensions: acpx labels Apr 1, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a051f35657

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@vincentkoc
vincentkoc merged commit 32ae841 into openclaw:main Apr 1, 2026
52 of 53 checks passed
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
…penclaw#57317)

* feat(web-search): add bundled searxng plugin

* test(web-search): cover searxng config wiring

* test(web-search): include searxng in bundled provider inventory

* test(web-search): keep searxng ordering aligned

* fix(web-search): sanitize searxng result rows

---------

Co-authored-by: Vincent Koc <[email protected]>
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…penclaw#57317)

* feat(web-search): add bundled searxng plugin

* test(web-search): cover searxng config wiring

* test(web-search): include searxng in bundled provider inventory

* test(web-search): keep searxng ordering aligned

* fix(web-search): sanitize searxng result rows

---------

Co-authored-by: Vincent Koc <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
…penclaw#57317)

* feat(web-search): add bundled searxng plugin

* test(web-search): cover searxng config wiring

* test(web-search): include searxng in bundled provider inventory

* test(web-search): keep searxng ordering aligned

* fix(web-search): sanitize searxng result rows

---------

Co-authored-by: Vincent Koc <[email protected]>
Nachx639 pushed a commit to Nachx639/clawdbot that referenced this pull request Jun 17, 2026
…penclaw#57317)

* feat(web-search): add bundled searxng plugin

* test(web-search): cover searxng config wiring

* test(web-search): include searxng in bundled provider inventory

* test(web-search): keep searxng ordering aligned

* fix(web-search): sanitize searxng result rows

---------

Co-authored-by: Vincent Koc <[email protected]>
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
…penclaw#57317)

* feat(web-search): add bundled searxng plugin

* test(web-search): cover searxng config wiring

* test(web-search): include searxng in bundled provider inventory

* test(web-search): keep searxng ordering aligned

* fix(web-search): sanitize searxng result rows

---------

Co-authored-by: Vincent Koc <[email protected]>
globalcaos pushed a commit to globalcaos/tinkerclaw that referenced this pull request Sep 29, 2026
…penclaw#57317)

* feat(web-search): add bundled searxng plugin

* test(web-search): cover searxng config wiring

* test(web-search): include searxng in bundled provider inventory

* test(web-search): keep searxng ordering aligned

* fix(web-search): sanitize searxng result rows

---------

Co-authored-by: Vincent Koc <[email protected]>
lhfer pushed a commit to lhfer/openclaw that referenced this pull request Oct 11, 2026
…penclaw#57317)

* feat(web-search): add bundled searxng plugin

* test(web-search): cover searxng config wiring

* test(web-search): include searxng in bundled provider inventory

* test(web-search): keep searxng ordering aligned

* fix(web-search): sanitize searxng result rows

---------

Co-authored-by: Vincent Koc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

web_search: Add SearXNG as fallback provider

2 participants