I am writing a small HTTP web server in C++ as part of a hobby project, and I need to serve static files. However, one problem I want to avoid is a user typing in, for example, http://example.com/../passwd
. To ensure that users don't enter in a malicious path, I want to check if a path entered is in the current parent directory.
My current approach is to use std::filesystem::directory_iterator
, checking if the provided one is a file and if its the same as the one provided. However, this is very slow and clunky, and I believe that there is a better solution.