From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 6EEAB1FF0B6 for ; Thu, 12 Nov 2026 05:44:17 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id A2F39215CB; Thu, 12 Nov 2026 05:44:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794458644; x=1795063444; darn=lists.proxmox.com; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=WemTnd5gaOHuHrMSiSBWTUeqHQ3o/VRUw5Pb4t8JjiQ=; b=loLcF34bPuZUYs3xNCXTFPVhCCiB5AblXP3QnJnw2xdby7t0jmPTuxKQL3ySxRpFCB tD5Kz77T4Y83hTfzc2j0XGYVYseZcM34fHD1/dTx7AJZ3N9D/c4YCo0waqquhmLoMlwJ RgasaoSjV/baivw8bdiD7foZS5vlGdQDUYG4nmiHMcZc8v1xYypwcvJKYx9m/Ufbykv0 4fL4MT5HN+w6Cl1xrs66gzicpI3/c0WW3KQTgS3/OdJVm1j36FRFDrDILRYz1XwsICVH c8fV9p5zVto+LBQd4jJSIt4SfAdFEw8W4VgbdIC+SRIWjxwcTSrvglXP424DozBT8Ec1 uwuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794458644; x=1795063444; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=WemTnd5gaOHuHrMSiSBWTUeqHQ3o/VRUw5Pb4t8JjiQ=; b=VZ+naR4qdpusDR+6Wh6kb1JU3xpJRIpXI1y+vS1pfQLetNTNZKt2TtcS3tLsbgsZlB zeD6UwhZigZ0KghR6h1OE8ACmdlboAK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KAuNAaH5ezA== X-Received: by 2002:a05:690c:dc5:b0:8b3:b358:f9e2 with SMTP id 00721157ae682-8b3b359071dmr20672717b3.103.1794458644378; Wed, 11 Nov 2026 20:44:04 -0800 (PST) From: Lucas Barros To: pbs-devel@lists.proxmox.com Subject: [PATCH proxmox] fix #8256: notify: webhook: do not follow redirects Date: Thu, 12 Nov 2026 01:43:57 -0300 Message-ID: <20261112044357.82306-1-lucasbarros.kam@gmail.com> X-Mailer: git-send-email 2.50.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.150 Adjusted score from AWL reputation of From: address DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain DMARC_PASS -0.1 DMARC pass policy FREEMAIL_FROM 0.001 Sender email is commonly abused enduser mail provider POISEN_SPAM_PILL 0.1 Meta: its spam POISEN_SPAM_PILL_1 0.1 random spam to be learned in bayes POISEN_SPAM_PILL_3 0.1 random spam to be learned in bayes RCVD_IN_DNSWL_NONE -0.0001 Sender listed at https://www.dnswl.org/, no trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: HMDCPI54GIOHX7QJG632AYLUSD5EEDGI X-Message-ID-Hash: HMDCPI54GIOHX7QJG632AYLUSD5EEDGI X-MailFrom: lucasbarros.kam@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Backup Server development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Webhook targets use the HTTP client with its default redirect handling. A POST or PUT that is answered with a redirect is then sent again as a GET to the new location, and the response to that is taken as a successful delivery. For example, Slack answers a request to a webhook URL with a malformed token with a redirect to its API documentation, so the notification is logged as sent and testing the target reports success, while nothing was delivered. Do not follow redirects for webhook targets and treat a redirect response as an error, mentioning the status and the location in the error message. Signed-off-by: Lucas Barros --- Reproduced on a PVE 9 node with a webhook target pointing to a local test server that answers POST /hook with '302 Location: /docs' and GET /docs with 200: $ pvesh create /cluster/notifications/targets/redir-test/test exit=0 requests received by the server: POST /hook GET /docs So the test of the target reports success, although the hook itself only got redirected. This is what the reporter saw with Slack. The new test does the same on a loopback socket. It fails without the change ('send' returns Ok) and passes with it; the rest of 'cargo test -p proxmox-notify --all-features' passes before and after (54 tests with the new one). The same could be done for gotify, which uses the same client, but the bug is only about webhooks, so I left it out. This patch was prepared with the help of an LLM based coding assistant; I reviewed the change and ran the tests mentioned above myself. proxmox-notify/src/endpoints/webhook.rs | 73 ++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/proxmox-notify/src/endpoints/webhook.rs b/proxmox-notify/src/endpoints/webhook.rs index f0fd5b6a..33bf6599 100644 --- a/proxmox-notify/src/endpoints/webhook.rs +++ b/proxmox-notify/src/endpoints/webhook.rs @@ -243,10 +243,26 @@ impl Endpoint for WebhookEndpoint { fn send(&self, notification: &Notification) -> Result<(), Error> { let request = self.build_request(notification)?; - self.create_client()? + let response = self + .create_client()? .request(request) .map_err(|err| self.mask_secret_in_error(err))?; + // Redirects are not followed, see create_client(). The notification was not delivered to + // the configured URL, so do not report success. + if response.status().is_redirection() { + let location = response + .headers() + .get(http::header::LOCATION) + .and_then(|value| value.to_str().ok()) + .unwrap_or_default(); + + return Err(self.mask_secret_in_error(format!( + "webhook request was answered with a redirect ({}) to '{location}'", + response.status() + ))); + } + Ok(()) } @@ -274,7 +290,9 @@ impl WebhookEndpoint { ..Default::default() }; - Ok(Client::new_with_timeout(options, HTTP_TIMEOUT)) + // Following a redirect would turn a POST or PUT into a GET to another URL and report its + // response, for example a documentation page, as a successful delivery. + Ok(Client::new_with_timeout(options, HTTP_TIMEOUT).with_max_redirects(0)) } fn build_request(&self, notification: &Notification) -> Result, Error> { @@ -570,4 +588,55 @@ hello%20world Ok(()) } + + #[test] + fn test_redirect_is_an_error() { + use std::io::{BufRead, BufReader, Write}; + use std::net::TcpListener; + + let listener = TcpListener::bind("127.0.0.1:0").unwrap(); + let addr = listener.local_addr().unwrap(); + + // answers with a redirect to a page on the same server, like a webhook URL with a wrong + // token that is redirected to a documentation page + std::thread::spawn(move || { + let responses = [ + format!("HTTP/1.1 302 Found\r\nLocation: http://{addr}/docs\r\n"), + "HTTP/1.1 200 OK\r\n".to_string(), + ]; + for response in responses { + let (mut stream, _) = listener.accept().unwrap(); + let mut reader = BufReader::new(stream.try_clone().unwrap()); + let mut line = String::new(); + while reader.read_line(&mut line).unwrap() > 2 { + line.clear(); + } + write!( + stream, + "{response}Content-Length: 0\r\nConnection: close\r\n\r\n" + ) + .unwrap(); + } + }); + + let endpoint = WebhookEndpoint { + config: WebhookConfig { + name: "test".into(), + method: HttpMethod::Post, + url: format!("http://{addr}/hook"), + ..Default::default() + }, + private_config: WebhookPrivateConfig { + name: "test".into(), + ..Default::default() + }, + }; + + let notification = + Notification::from_template(Severity::Info, "foo", json!({}), HashMap::new()); + + let err = endpoint.send(¬ification).unwrap_err(); + + assert!(err.to_string().contains("redirect (302 Found)"), "{err}"); + } } -- 2.47.3