From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 241761FF0C0 for ; Wed, 18 Nov 2026 10:48:31 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 903C221AB1; Wed, 18 Nov 2026 10:44:59 +0100 (CET) From: Lukas Wagner To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox v2 40/63] notify: make sure that template name matches SAFE_ID_REGEX Date: Wed, 18 Nov 2026 10:43:24 +0100 Message-ID: <20261118094348.273646-41-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261118094348.273646-1-l.wagner@proxmox.com> References: <20261118094348.273646-1-l.wagner@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794995040054 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.192 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium 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: L74ZWBZXIE3VIRHACQDMVU24WFWMYNRG X-Message-ID-Hash: L74ZWBZXIE3VIRHACQDMVU24WFWMYNRG X-MailFrom: l.wagner@proxmox.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 VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: This avoids malformed template identifiers which could read from outside the template base directory. The template name is checked when constructing a notification, but also on `send`. Signed-off-by: Lukas Wagner --- Notes: New in v2. proxmox-notify/src/notification.rs | 54 ++++++++++++++++++++++++++++-- proxmox-notify/src/send.rs | 2 ++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/proxmox-notify/src/notification.rs b/proxmox-notify/src/notification.rs index b1756a5d7..efb3508f1 100644 --- a/proxmox-notify/src/notification.rs +++ b/proxmox-notify/src/notification.rs @@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; use proxmox_schema::api; +use proxmox_schema::api_types::{SAFE_ID_REGEX, SAFE_ID_REGEX_STR}; use proxmox_uuid::Uuid; use crate::Error; @@ -199,6 +200,15 @@ impl Notification { pub fn recipient(&self) -> &Recipient { &self.recipient } + + /// Validate this notification. + pub fn validate(&self) -> Result<(), Error> { + if let Content::Template { template_name, .. } = &self.content { + verify_template_name(template_name)?; + } + + Ok(()) + } } /// Builder for [`Notification`]. @@ -247,7 +257,7 @@ impl NotificationBuilder { /// Build the notification, assigning a new unique ID and the current time as timestamp. pub fn build(self) -> Result { - Ok(Notification { + let notification = Notification { content: self.content?, metadata: Metadata { severity: self.severity.unwrap_or(Severity::Unknown), @@ -256,10 +266,24 @@ impl NotificationBuilder { }, id: Uuid::generate(), recipient: self.recipient, - }) + }; + + notification.validate()?; + + Ok(notification) } } +pub(crate) fn verify_template_name(name: &str) -> Result<(), Error> { + if !SAFE_ID_REGEX.is_match(name) { + return Err(Error::invalid_notification(format!( + "template name '{name}' does not match regex '{SAFE_ID_REGEX_STR}'" + ))); + } + + Ok(()) +} + #[cfg(test)] mod tests { use serde_json::json; @@ -425,4 +449,30 @@ mod tests { assert_eq!(deserialized, notification); } } + + #[test] + /// Verify that it is not possible to construct notifications + /// with invalid template names. + fn invalid_template_name() { + assert!( + Notification::template_builder("../something", ()) + .build() + .is_err() + ); + assert!( + Notification::template_builder("/foo/bar", ()) + .build() + .is_err() + ); + assert!( + Notification::template_builder("../../foo/bar", ()) + .build() + .is_err() + ); + assert!( + Notification::template_builder("invälid", ()) + .build() + .is_err() + ); + } } diff --git a/proxmox-notify/src/send.rs b/proxmox-notify/src/send.rs index 9fc3864ed..c11ff1b76 100644 --- a/proxmox-notify/src/send.rs +++ b/proxmox-notify/src/send.rs @@ -24,6 +24,8 @@ pub fn send( config: &Config, notification: &Notification, ) -> Result { + notification.validate()?; + let bus = Bus::from_config(config)?; Ok(bus.send(context, notification)) } -- 2.47.3