fix(web_fetch): 禁用 HTTP 重定向,防止 SSRF 重定向绕过

validate_url 只校验初始 URL 的 host,若跟随 302 跳转,攻击者可用公网 URL
重定向到 169.254.169.254(云元数据)或 127.0.0.1 等内网地址,绕过 is_private_host
的 SSRF 防护。与 http_request 工具保持一致,使用 redirect::Policy::none()。
This commit is contained in:
oudecheng 2026-08-04 08:25:57 +08:00
parent 94a0dd0169
commit 1e2d64e28b

View File

@ -64,6 +64,11 @@ impl WebFetchTool {
async fn fetch_content(&self, url: &str) -> Result<String, String> {
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(self.timeout_secs))
// 禁用重定向validate_url 只校验初始 URL 的 host
// 若跟随 302 跳转,攻击者可用公网 URL 重定向到
// 169.254.169.254(云元数据)或 127.0.0.1 等内网地址,
// 绕过 is_private_host 的 SSRF 防护。
.redirect(reqwest::redirect::Policy::none())
.build()
.map_err(|e| format!("Failed to create HTTP client: {}", e))?;