mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-26 12:24:46 +00:00
Refuse a ':' in a path a mount point serves on Windows (#2643)
On NTFS a ':' in a path names a stream of the file, so /dir/test.html::$DATA opened the default stream of dir/test.html and passed a set_pre_routing_handler() guard on /dir/test.html, and /setup.exe:Zone.Identifier served the stream Windows attaches to downloaded files. is_valid_path() now refuses a ':' on Windows. Elsewhere a ':' is an ordinary file name character, so it is still served: a file such as 2024-01-01T10:00:00.log would otherwise answer 404. The test pins both sides.
This commit is contained in:
1 parent
2f8b9f6f57
commit
8710fbd25d
3 files changed
+22
-5
No files matched your search
@@ -6007,9 +6007,10 @@ inline bool is_valid_close_payload(const std::string &payload) {
|
||||
namespace detail {
|
||||
|
||||
// A path a mount point serves: absolute, with no empty segment except a
|
||||
// trailing '/' and no segment ending in '.' or a space (which covers "." and
|
||||
// ".." and names Windows trims into another file's name), so the file served
|
||||
// is the one that req.path names to the handlers that ran before it.
|
||||
// trailing '/', no segment ending in '.' or a space (which covers "." and
|
||||
// ".." and names Windows trims into another file's name) and, on Windows, no
|
||||
// ':' (which names an NTFS stream, so "a.txt::$DATA" is a.txt), so the file
|
||||
// served is the one that req.path names to the handlers that ran before it.
|
||||
inline bool is_valid_path(const std::string &path) {
|
||||
if (path.empty() || path[0] != '/') { return false; }
|
||||
|
||||
@@ -6017,6 +6018,9 @@ inline bool is_valid_path(const std::string &path) {
|
||||
for (auto i = beg; i <= path.size(); i++) {
|
||||
if (i < path.size() && path[i] != '/') {
|
||||
if (path[i] == '\0' || path[i] == '\\') { return false; }
|
||||
#ifdef _WIN32
|
||||
if (path[i] == ':') { return false; }
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
auto len = i - beg;
|
||||
|
||||
Reference in new issue
Block a user