From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id EB9561FF399 for ; Fri, 7 Jun 2024 13:48:23 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 649D51E4E9; Fri, 7 Jun 2024 13:48:54 +0200 (CEST) From: Gabriel Goller To: pbs-devel@lists.proxmox.com Date: Fri, 7 Jun 2024 13:48:35 +0200 Message-ID: <20240607114846.321729-5-g.goller@proxmox.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240607114846.321729-1-g.goller@proxmox.com> References: <20240607114846.321729-1-g.goller@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.060 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pbs-devel] [PATCH proxmox v3 4/7] rest-server: add custom handlebars escape fn X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" Add a custom handlebars escape function. It's nearly identical to the default `html_escape` fn [0], but it does not escape the '='. This is needed to support base64 encoded values. [0]: https://docs.rs/handlebars/latest/handlebars/fn.html_escape.html Signed-off-by: Gabriel Goller --- proxmox-rest-server/src/api_config.rs | 28 ++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/proxmox-rest-server/src/api_config.rs b/proxmox-rest-server/src/api_config.rs index eaece05a..bf311f4b 100644 --- a/proxmox-rest-server/src/api_config.rs +++ b/proxmox-rest-server/src/api_config.rs @@ -60,7 +60,7 @@ impl ApiConfig { privileged_addr: None, #[cfg(feature = "templates")] - templates: Default::default(), + templates: templates::Templates::with_escape_fn(), } } @@ -333,6 +333,32 @@ mod templates { } impl Templates { + pub fn with_escape_fn() -> Templates { + let mut registry = Handlebars::new(); + // This is the same as the default `html_escape` fn in + // handlebars, **but** it does not escape the '='. This + // is to preserve base64 values. + registry.register_escape_fn(|value| { + let mut output = String::new(); + for c in value.chars() { + match c { + '<' => output.push_str("<"), + '>' => output.push_str(">"), + '"' => output.push_str("""), + '&' => output.push_str("&"), + '\'' => output.push_str("'"), + '`' => output.push_str("`"), + _ => output.push(c), + } + } + output + }); + Self { + templates: RwLock::new(registry), + template_files: RwLock::new(HashMap::new()), + } + } + pub fn register

(&self, name: &str, path: P) -> Result<(), Error> where P: Into, -- 2.43.0 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel