From 9d2616e8bac4fcb32497b8afdcfb28019e0803a6 Mon Sep 17 00:00:00 2001 From: Vladimir Dubrovin <3proxy@3proxy.ru> Date: Sun, 8 Nov 2026 14:39:50 +0300 Subject: [PATCH] httpsrv: a dot-dot segment of a path refused, with either separator A path ending in a backslashed dot-dot, or carrying one in a form the checks did not name, was taken as it stood. Any dot-dot segment is now refused wherever it is and whichever separator carries it, and a path ending in a bare dot of either kind. (cherry picked from commit c0eb7a65c6dede534ebe07b1bb97d248fcc4a861) --- src/httpsrv.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/httpsrv.c b/src/httpsrv.c index d9bcc92..c41c206 100644 --- a/src/httpsrv.c +++ b/src/httpsrv.c @@ -430,11 +430,12 @@ static int targetunsafe(const char *path) #endif } if(!strncmp(path, "./", 2) || !strncmp(path, "../", 3)) return 1; - if(strstr(path, "/./") || strstr(path, "/../")) return 1; - if(strstr(path, "\\.\\") || strstr(path, "\\..\\")) return 1; + /* a dot-dot segment, with either separator, wherever it is in the + path: a walk out of the tree, or a file named to look like one */ + if(strstr(path, "/..") || strstr(path, "\\..")) return 1; + if(strstr(path, "/./") || strstr(path, "\\.\\")) return 1; p = path + strlen(path); - if(p - path >= 2 && !strcmp(p - 2, "/.")) return 1; - if(p - path >= 3 && !strcmp(p - 3, "/..")) return 1; + if(p - path >= 2 && (!strcmp(p - 2, "/.") || !strcmp(p - 2, "\\."))) return 1; return 0; }