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
+28 -3
View File
@@ -241,17 +241,38 @@ services:
networks:
- WeKnora-network
# One-shot init: copy the read-only template settings.yml into a named volume
# before searxng starts. Necessary because the searxng entrypoint sed-replaces
# `ultrasecretkey` in /etc/searxng/settings.yml in place; bind-mounting the
# repo file directly would write the resolved SEARXNG_SECRET back into the
# working tree (and prevent re-templating on subsequent restarts).
searxng-init:
image: busybox:1.36
container_name: WeKnora-searxng-init
command: ["sh", "-c", "cp /template/settings.yml /etc/searxng/settings.yml && chmod 0644 /etc/searxng/settings.yml"]
volumes:
- ./docker/searxng/settings.yml:/template/settings.yml:ro
- searxng_config:/etc/searxng
restart: "no"
networks:
- WeKnora-network
profiles:
- searxng
- full
searxng:
image: searxng/searxng:latest
container_name: WeKnora-searxng
# Bind to loopback by default; override SEARXNG_BIND=0.0.0.0 only after
# rotating SEARXNG_SECRET and (optionally) re-enabling limiter in settings.yml.
ports:
- "${SEARXNG_PORT:-8888}:8080"
- "${SEARXNG_BIND:-127.0.0.1}:${SEARXNG_PORT:-8888}:8080"
volumes:
- ./docker/searxng/settings.yml:/etc/searxng/settings.yml:rw
- searxng_config:/etc/searxng
environment:
- SEARXNG_BASE_URL=http://localhost:${SEARXNG_PORT:-8888}/
- INSTANCE_NAME=weknora-searxng
- SEARXNG_SECRET=${SEARXNG_SECRET:-please-change-me-to-a-long-random-string}
- SEARXNG_SECRET=${SEARXNG_SECRET:?SEARXNG_SECRET must be set (e.g. openssl rand -hex 32) before starting the searxng profile}
cap_drop:
- ALL
cap_add:
@@ -259,6 +280,9 @@ services:
- SETGID
- SETUID
restart: unless-stopped
depends_on:
searxng-init:
condition: service_completed_successfully
networks:
- WeKnora-network
profiles:
@@ -707,3 +731,4 @@ volumes:
langfuse_clickhouse_data:
langfuse_clickhouse_logs:
langfuse_minio_data:
searxng_config: