From c593fbb3b4c47cc6bc8d35b8753a229b14944551 Mon Sep 17 00:00:00 2001 From: Michael Schreckenbauer Date: Wed, 15 Jun 2022 09:20:11 +0200 Subject: [PATCH 1/4] only allow regular files in set_static_file_info, return 404 in all other cases --- include/crow/http_response.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/crow/http_response.h b/include/crow/http_response.h index ec667b9a4..ce6ef2cad 100644 --- a/include/crow/http_response.h +++ b/include/crow/http_response.h @@ -233,7 +233,7 @@ namespace crow #ifdef CROW_ENABLE_COMPRESSION compressed = false; #endif - if (file_info.statResult == 0) + if (file_info.statResult == 0 && S_ISREG(file_info.statbuf.st_mode)) { std::size_t last_dot = path.find_last_of("."); std::string extension = path.substr(last_dot + 1); @@ -257,7 +257,6 @@ namespace crow { code = 404; file_info.path.clear(); - this->end(); } } From df3d7cad41fa13981d688286e006b1f322526eff Mon Sep 17 00:00:00 2001 From: Michael Schreckenbauer Date: Wed, 22 Jun 2022 10:54:25 +0200 Subject: [PATCH 2/4] define S_ISREG on windows --- include/crow/http_response.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/crow/http_response.h b/include/crow/http_response.h index ce6ef2cad..922031027 100644 --- a/include/crow/http_response.h +++ b/include/crow/http_response.h @@ -4,7 +4,15 @@ #include #include #include +#if defined(_MSC_VER) +#define _CRT_INTERNAL_NONSTDC_NAMES 1 #include +#if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG) +#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG) +#endif +#else +#include +#endif #include "crow/http_request.h" #include "crow/ci_map.h" From 5f73f39ea705e773b1c71f3b59aba5921ec27a9c Mon Sep 17 00:00:00 2001 From: MichaelSB Date: Wed, 22 Jun 2022 14:54:52 +0200 Subject: [PATCH 3/4] Simplified condition for defining S_ISREG Co-authored-by: Farook Al-Sammarraie --- include/crow/http_response.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/include/crow/http_response.h b/include/crow/http_response.h index 922031027..b5ff6eea8 100644 --- a/include/crow/http_response.h +++ b/include/crow/http_response.h @@ -6,13 +6,11 @@ #include #if defined(_MSC_VER) #define _CRT_INTERNAL_NONSTDC_NAMES 1 +#endif #include #if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG) #define S_ISREG(m) (((m)&S_IFMT) == S_IFREG) #endif -#else -#include -#endif #include "crow/http_request.h" #include "crow/ci_map.h" From 83cde80023a332e317934d34db8bfcb1c093ba9a Mon Sep 17 00:00:00 2001 From: Michael Schreckenbauer Date: Wed, 22 Jun 2022 15:00:00 +0200 Subject: [PATCH 4/4] added comment on S_ISREG --- include/crow/http_response.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/crow/http_response.h b/include/crow/http_response.h index b5ff6eea8..ab25db2da 100644 --- a/include/crow/http_response.h +++ b/include/crow/http_response.h @@ -4,6 +4,8 @@ #include #include #include +// S_ISREG is not defined for windows +// This defines it like suggested in https://stackoverflow.com/a/62371749 #if defined(_MSC_VER) #define _CRT_INTERNAL_NONSTDC_NAMES 1 #endif