From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 17579A2B89 for ; Tue, 20 Jun 2023 12:39:51 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id ECFF6336F2 for ; Tue, 20 Jun 2023 12:39:50 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Tue, 20 Jun 2023 12:39:50 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 0A1AD41C11 for ; Tue, 20 Jun 2023 12:39:50 +0200 (CEST) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pbs-devel@lists.proxmox.com Date: Tue, 20 Jun 2023 12:39:45 +0200 Message-Id: <20230620103945.3969702-1-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.071 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 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [proxmox.com, rest.rs] Subject: [pbs-devel] [PATCH proxmox] rest: remove full static file path from error messages 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: , X-List-Received-Date: Tue, 20 Jun 2023 10:39:51 -0000 this triggers certain security scanners, and having the requested path instead gives basically the same information anyhow. reported on the forum: https://forum.proxmox.com/threads/404-path-disclosure-vulnerability.129187/ Signed-off-by: Fabian Grünbichler --- with EPERM for example, this would return File open failed for 'foobar': permission denied instead of File open failed: Permission denied (os error 13) and for missing files it would return no such file: 'foobar' instead of no such file: "/usr/share/javascript/proxmox-backup/foobar" proxmox-rest-server/src/rest.rs | 39 +++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/proxmox-rest-server/src/rest.rs b/proxmox-rest-server/src/rest.rs index 100c93c..d22a35e 100644 --- a/proxmox-rest-server/src/rest.rs +++ b/proxmox-rest-server/src/rest.rs @@ -620,16 +620,12 @@ fn extension_to_content_type(filename: &Path) -> (&'static str, bool) { } async fn simple_static_file_download( - filename: PathBuf, + mut file: File, content_type: &'static str, compression: Option, ) -> Result, Error> { use tokio::io::AsyncReadExt; - let mut file = File::open(filename) - .await - .map_err(|err| http_err!(BAD_REQUEST, "File open failed: {}", err))?; - let mut data: Vec = Vec::new(); let mut response = match compression { @@ -660,8 +656,8 @@ async fn simple_static_file_download( Ok(response) } -async fn chuncked_static_file_download( - filename: PathBuf, +async fn chunked_static_file_download( + file: File, content_type: &'static str, compression: Option, ) -> Result, Error> { @@ -669,10 +665,6 @@ async fn chuncked_static_file_download( .status(StatusCode::OK) .header(header::CONTENT_TYPE, content_type); - let file = File::open(filename) - .await - .map_err(|err| http_err!(BAD_REQUEST, "File open failed: {}", err))?; - let body = match compression { Some(CompressionMethod::Deflate) => { resp = resp.header( @@ -691,24 +683,39 @@ async fn chuncked_static_file_download( } async fn handle_static_file_download( + components: &[&str], filename: PathBuf, compression: Option, ) -> Result, Error> { let metadata = match tokio::fs::metadata(filename.clone()).await { Ok(metadata) => metadata, Err(err) if err.kind() == io::ErrorKind::NotFound => { - http_bail!(NOT_FOUND, "no such file: {filename:?}") + http_bail!(NOT_FOUND, "no such file: '{}'", components.join("/")) } - Err(err) => http_bail!(BAD_REQUEST, "File access problems: {}", err), + Err(err) => http_bail!( + BAD_REQUEST, + "File access problem on '{}': {}", + components.join("/"), + err.kind() + ), }; let (content_type, nocomp) = extension_to_content_type(&filename); let compression = if nocomp { None } else { compression }; + let file = File::open(filename).await.map_err(|err| { + http_err!( + BAD_REQUEST, + "File open failed for '{}': {}", + components.join("/"), + err.kind() + ) + })?; + if metadata.len() < CHUNK_SIZE_LIMIT { - simple_static_file_download(filename, content_type, compression).await + simple_static_file_download(file, content_type, compression).await } else { - chuncked_static_file_download(filename, content_type, compression).await + chunked_static_file_download(file, content_type, compression).await } } @@ -782,7 +789,7 @@ impl ApiConfig { } else { let filename = self.find_alias(&components); let compression = extract_compression_method(&parts.headers); - return handle_static_file_download(filename, compression).await; + return handle_static_file_download(&components, filename, compression).await; } } } -- 2.39.2