feat(searxng): enhance SearXNG configuration and validation

- Updated .env.example to clarify SEARXNG_SECRET generation and added SSRF_WHITELIST_EXTRA for improved security.
- Modified docker-compose files to bind SearXNG to localhost by default and introduced a one-time initialization service to set up settings.yml correctly.
- Enhanced SearxngProvider with stricter URL validation, ensuring no query or fragment is present in the base URL.
- Added unit tests for SearXNG validation and date parsing to ensure robustness.
- Updated frontend WebSearchSettings to reflect changes in SearXNG instance URL handling.

This commit improves the security and usability of the SearXNG integration, addressing potential misconfigurations and enhancing the developer experience.
This commit is contained in:
wizardchen
2026-05-10 22:51:24 +08:00
committed by lyingbug
parent d2a1006beb
commit 0f5dc41f4e
7 changed files with 232 additions and 14 deletions
+18 -4
View File
@@ -204,11 +204,25 @@ SYSTEM_AES_KEY=weknora-system-aes-key-32bytes!!
# SSRF_WHITELIST=internal.service,*.corp.example,172.16.0.0/12,2001:db8::1,fd00::/8
# ===== SearXNG(可选自建网络搜索)=====
# 启用:docker compose --profile searxng up -d
# 默认对外端口 8888,容器内主机名 searxng:8080;后端通过 docker network 直接访问。
# WeKnora 控制台中 Provider 类型选 "SearXNG",Instance URL 填 http://searxng:8080 即可。
# 启用:先生成强随机 SEARXNG_SECRET,再 `docker compose --profile searxng up -d`。
# openssl rand -hex 32
# 没有 SEARXNG_SECRET 时 docker compose 会主动报错,避免使用公开默认值。
#
# 后端访问方式(容器化部署):控制台中 Provider 类型选 "SearXNG",
# Instance URL 填 http://searxng:8080 ;docker compose 已默认把 `searxng` 主机名
# 注入 SSRF_WHITELIST_EXTRA,无需额外配置。
#
# 本地开发(go run + docker compose -f docker-compose.dev.yml --profile searxng up):
# 后端跑在宿主机,需走 published 端口;Instance URL 填 http://127.0.0.1:8888 ,
# 并把 127.0.0.1 加入下方 SSRF_WHITELIST:
# SSRF_WHITELIST=127.0.0.1
#
# 端口默认仅监听 127.0.0.1,避免把开了 limiter:false 的实例暴露到 LAN。
# 如需对内网开放,显式覆盖 SEARXNG_BIND=0.0.0.0 并自行加固。
# SEARXNG_PORT=8888
# SEARXNG_SECRET=please-change-me-to-a-long-random-string # openssl rand -hex 32
# SEARXNG_BIND=127.0.0.1
# SEARXNG_SECRET=
# SSRF_WHITELIST_EXTRA=searxng
# 是否开启知识图谱构建和检索(构建阶段需调用大模型,耗时较长)
ENABLE_GRAPH_RAG=false