Browse Source

Issue 2377 – Avoid replacing %2F with a slash and %2E with a dot in special cases on upload to avoid path traversal

https://winscp.net/tracker/2377
(cherry picked from commit 0071ffadacc2fb23e5369fc7b8dbd2f5fd2d5303)

Source commit: a39cab9e6e4fa35e37712cfc7d73e459a0e2d577
Martin Prikryl 5 months ago
parent
commit
d39f87c8ca
1 changed files with 3 additions and 2 deletions
  1. 3 2
      source/core/CopyParam.cpp

+ 3 - 2
source/core/CopyParam.cpp

@@ -631,9 +631,10 @@ UnicodeString __fastcall TCopyParamType::RestoreChars(UnicodeString FileName) co
       {
         UnicodeString Hex = FileName.SubString(Index + 1, 2);
         wchar_t Char = static_cast<wchar_t>(HexToByte(Hex));
-        if ((Char != L'\0') &&
+        if ((Char != L'\0') && (Char != L'/') &&
             ((FTokenizibleChars.Pos(Char) > 0) ||
-             (((Char == L' ') || (Char == L'.')) && (Index == FileName.Length() - 2))))
+             // not decoding lone dot
+             (((Char == L' ') || ((Char == L'.') && (Index > 1))) && (Index == FileName.Length() - 2))))
         {
           FileName[Index] = Char;
           FileName.Delete(Index + 1, 2);