From 525129ddcbe18119f87705caaefa37a4e3a11872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Wed, 16 Mar 2022 16:37:54 +0300 Subject: [PATCH] fix(server): check if the path is a file while serving closes #19 --- src/server.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/server.rs b/src/server.rs index 7b56d3e..b40d0b6 100644 --- a/src/server.rs +++ b/src/server.rs @@ -50,10 +50,12 @@ async fn serve( } } } + if !path.is_file() || !path.exists() { + return Err(error::ErrorNotFound("file is not found or expired :(")); + } match paste_type { PasteType::File | PasteType::RemoteFile | PasteType::Oneshot => { - let response = NamedFile::open(&path) - .map_err(|_| error::ErrorNotFound("file is not found or expired :("))? + let response = NamedFile::open(&path)? .disable_content_disposition() .set_content_type( mime::get_mime_type(&config.paste.mime_override, file.to_string())