mirror of
https://github.com/2dust/v2rayN.git
synced 2026-11-17 09:55:00 +03:00
Prevent zip path traversal in app upgrade
Hardened upgrade extraction by validating each zip entry resolves under the app startup directory before writing files, and aborting with a clear failure message on suspicious paths. Added shared path utilities for directory containment checks and OS-aware path string comparison, then reused them for executable matching and `bin` prefix checks during extraction. https://github.com/2dust/v2rayN/issues/10313
This commit is contained in:
@@ -24,6 +24,28 @@ internal class Utils
|
||||
return Path.Combine(startupPath, fileName);
|
||||
}
|
||||
|
||||
public static bool IsPathUnderDirectory(string baseDir, string targetPath)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(baseDir) || string.IsNullOrWhiteSpace(targetPath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var baseFull = Path.GetFullPath(baseDir);
|
||||
var targetFull = Path.GetFullPath(targetPath);
|
||||
|
||||
baseFull = baseFull.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar) + Path.DirectorySeparatorChar;
|
||||
|
||||
return targetFull.StartsWith(baseFull, GetPathComparison());
|
||||
}
|
||||
|
||||
public static StringComparison GetPathComparison()
|
||||
{
|
||||
return OperatingSystem.IsWindows()
|
||||
? StringComparison.OrdinalIgnoreCase
|
||||
: StringComparison.Ordinal;
|
||||
}
|
||||
|
||||
public static string V2rayN => "v2rayN";
|
||||
|
||||
public static void StartV2RayN()
|
||||
|
||||
Reference in New Issue
Block a user