WeKnora/internal/infrastructure/web_search
ordinary being c44f939211
fix(web-search): bound provider response bodies instead of buffering them whole (#4370)
Every provider read its response with an unbounded io.ReadAll, or handed
resp.Body straight to json.NewDecoder, so a misconfigured or hostile endpoint
decided how much memory a single search allocated. Two providers made it worse
by reading before they looked at the status code and then interpolating the whole
body into both a log line and the error the caller sees - so a failing endpoint
could push an unbounded blob into the error string as well as into memory.

Reuse the cap the datasource connectors already apply to their API bodies
(readCapped + maxJSONResponseBytes + errResponseTooLarge, added for feishu, ima,
notion and yuque in #3985) rather than inventing a second dialect here. Apply it
to the six providers that read a response body, and bound failed-response
previews the way searxng.go already bounded its own and the connectors bound
theirs.

The two providers that decoded straight from resp.Body now buffer through
readCapped first, since a decoder cannot be capped without buffering.
2026-10-16 17:16:39 +08:00
..
baidu.go fix(security): harden outbound URL SSRF protection (#2626) 2026-08-10 13:24:14 +08:00
bing.go fix(web-search): bound provider response bodies instead of buffering them whole (#4370) 2026-10-16 17:16:39 +08:00
bocha.go feat(web-search): add Bocha AI Search provider (#3036) 2026-09-07 20:06:26 +08:00
bocha_test.go feat(web-search): add Bocha AI Search provider (#3036) 2026-09-07 20:06:26 +08:00
brave.go fix(agent): improve web search and persistent page reading (#3086) 2026-09-07 23:09:27 +08:00
brave_test.go fix(agent): improve web search and persistent page reading (#3086) 2026-09-07 23:09:27 +08:00
duckduckgo.go fix(web-search): bound provider response bodies instead of buffering them whole (#4370) 2026-10-16 17:16:39 +08:00
exa.go feat: add Exa WebSearch (#2617) 2026-08-11 17:05:52 +08:00
exa_test.go feat: add Exa WebSearch (#2617) 2026-08-11 17:05:52 +08:00
google.go feat: search engine adds proxy addresses and adds SSRF verification. 2026-04-17 16:38:02 +08:00
keenable.go fix(web-search): bound provider response bodies instead of buffering them whole (#4370) 2026-10-16 17:16:39 +08:00
keenable_test.go fix(web-search): polish Keenable provider integration after #1946 2026-07-07 17:14:39 +08:00
metaso.go fix(websearch): return results for non-webpage Metaso scopes (#4010) 2026-10-10 10:25:40 +08:00
metaso_test.go fix(websearch): return results for non-webpage Metaso scopes (#4010) 2026-10-10 10:25:40 +08:00
ollama.go fix(web-search): bound provider response bodies instead of buffering them whole (#4370) 2026-10-16 17:16:39 +08:00
proxy.go fix(security): harden outbound URL SSRF protection (#2626) 2026-08-10 13:24:14 +08:00
proxy_test.go fix(security): harden outbound URL SSRF protection (#2626) 2026-08-10 13:24:14 +08:00
registry.go revert: take the plugin system back out of main 2026-09-26 14:58:18 +08:00
response_limit.go fix(web-search): bound provider response bodies instead of buffering them whole (#4370) 2026-10-16 17:16:39 +08:00
response_limit_test.go fix(web-search): bound provider response bodies instead of buffering them whole (#4370) 2026-10-16 17:16:39 +08:00
searxng.go fix(web-search): bound provider response bodies instead of buffering them whole (#4370) 2026-10-16 17:16:39 +08:00
searxng_test.go fix(web-search): improve SearXNG test connection error messages 2026-06-24 14:28:49 +08:00
serply.go feat(web-search): add Serply provider 2026-09-17 12:25:09 +08:00
serply_test.go feat(web-search): add Serply provider 2026-09-17 12:25:09 +08:00
tavily.go fix(web-search): bound provider response bodies instead of buffering them whole (#4370) 2026-10-16 17:16:39 +08:00
test_errors.go feat: add Exa WebSearch (#2617) 2026-08-11 17:05:52 +08:00
test_errors_test.go feat: add Exa WebSearch (#2617) 2026-08-11 17:05:52 +08:00
zhipu.go feat(web-search): add Zhipu AI web search provider support 2026-07-20 12:15:35 +08:00
zhipu_test.go feat(web-search): add Zhipu AI web search provider support 2026-07-20 12:15:35 +08:00