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
+37
View File
@@ -212,6 +212,43 @@ func TestValidateURLForSSRF_IPv6Whitelist(t *testing.T) {
}
}
// TestSSRFWhitelistExtraMerge verifies that SSRF_WHITELIST_EXTRA is merged
// into the effective whitelist alongside SSRF_WHITELIST, so deployment-managed
// defaults (e.g. docker-compose injected sidecar host names) survive when an
// operator overrides SSRF_WHITELIST in their .env.
func TestSSRFWhitelistExtraMerge(t *testing.T) {
cases := []struct {
name string
main string
extra string
host string
want bool
}{
{name: "extra only", main: "", extra: "searxng", host: "searxng", want: true},
{name: "main only does not match extra host", main: "internal", extra: "", host: "searxng", want: false},
{name: "both merged - main host", main: "internal", extra: "searxng", host: "internal", want: true},
{name: "both merged - extra host", main: "internal", extra: "searxng", host: "searxng", want: true},
{name: "neither matches unrelated host", main: "internal", extra: "searxng", host: "evil.example", want: false},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
resetSSRFWhitelistForTest()
os.Setenv("SSRF_WHITELIST", tc.main)
os.Setenv("SSRF_WHITELIST_EXTRA", tc.extra)
defer func() {
os.Unsetenv("SSRF_WHITELIST")
os.Unsetenv("SSRF_WHITELIST_EXTRA")
resetSSRFWhitelistForTest()
}()
if got := IsSSRFWhitelisted(tc.host); got != tc.want {
t.Fatalf("IsSSRFWhitelisted(%q) main=%q extra=%q = %v, want %v",
tc.host, tc.main, tc.extra, got, tc.want)
}
})
}
}
// TestIsRestrictedIP_IPv6 tests IPv6-specific restricted range detection.
func TestIsRestrictedIP_IPv6(t *testing.T) {
t.Parallel()