Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/System.Management.Automation/engine/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,11 @@ internal static bool IsValidPSEditionValue(string editionValue)
/// </summary>
internal const string ProductNameForDirectory = "PowerShell";

/// <summary>
/// WSL introduces a new filesystem path to access the Linux filesystem from Windows, like '\\wsl$\ubuntu'.
/// </summary>
internal const string WslRootPath = @"\\wsl$";

/// <summary>
/// The subdirectory of module paths
/// e.g. ~\Documents\WindowsPowerShell\Modules and %ProgramFiles%\WindowsPowerShell\Modules.
Expand Down Expand Up @@ -1289,7 +1294,7 @@ internal static bool PathIsUnc(string path)
}

// handle special cases like \\wsl$\ubuntu which isn't a UNC path, but we can say it is so the filesystemprovider can use it
if (path.StartsWith(@"\\wsl$", StringComparison.OrdinalIgnoreCase))
if (path.StartsWith(WslRootPath, StringComparison.OrdinalIgnoreCase))
{
return true;
}
Expand Down
13 changes: 12 additions & 1 deletion src/System.Management.Automation/utils/ClrFacade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,19 @@ internal static SecurityZone GetFileSecurityZone(string filePath)
/// </remarks>
private static SecurityZone MapSecurityZone(string filePath)
{
// WSL introduces a new filesystem path to access the Linux filesystem from Windows, like '\\wsl$\ubuntu'.
// If the given file path is such a special case, we consider it's in 'MyComputer' zone.
if (filePath.StartsWith(Utils.WslRootPath, StringComparison.OrdinalIgnoreCase))
{
return SecurityZone.MyComputer;
}

SecurityZone reval = ReadFromZoneIdentifierDataStream(filePath);
if (reval != SecurityZone.NoZone) { return reval; }
if (reval != SecurityZone.NoZone)
{
return reval;
}

// If it reaches here, then we either couldn't get the ZoneId information, or the ZoneId is invalid.
// In this case, we try to determine the SecurityZone by analyzing the file path.
Uri uri = new Uri(filePath);
Expand Down