From da539efb98b47265a31160b5da930819bddfcc22 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sat, 13 Jan 2024 18:09:37 -0500 Subject: [PATCH] only follow up to 6 redirects in default reqwest ClientBuilder Signed-off-by: strawberry --- src/service/globals/mod.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/service/globals/mod.rs b/src/service/globals/mod.rs index 89e85fd4..78d913e7 100644 --- a/src/service/globals/mod.rs +++ b/src/service/globals/mod.rs @@ -539,10 +539,19 @@ impl Service<'_> { } fn reqwest_client_builder(config: &Config) -> Result { + let redirect_policy = reqwest::redirect::Policy::custom(|attempt| { + if attempt.previous().len() > 6 { + attempt.error("Too many redirects (max is 6)") + } else { + attempt.follow() + } + }); + let mut reqwest_client_builder = reqwest::Client::builder() .pool_max_idle_per_host(0) .connect_timeout(Duration::from_secs(60)) .timeout(Duration::from_secs(60 * 5)) + .redirect(redirect_policy) .user_agent(concat!( env!("CARGO_PKG_NAME"), "/",