diff --git a/scripts/Invoke-M4DetectorShadow.ps1 b/scripts/Invoke-M4DetectorShadow.ps1 index 8545f59..960f0ab 100644 --- a/scripts/Invoke-M4DetectorShadow.ps1 +++ b/scripts/Invoke-M4DetectorShadow.ps1 @@ -114,10 +114,17 @@ function Write-Utf8NoBom([string]$Path, [string]$Value) { } function Get-DirectoryTreeSha256([string]$Root, [object[]]$Files) { + $rootPrefix = $Root.TrimEnd("\") + "\" $rows = @( foreach ($file in $Files) { + if (-not $file.FullName.StartsWith( + $rootPrefix, + [StringComparison]::OrdinalIgnoreCase + )) { + throw "M4 dependency file escaped its declared root" + } [pscustomobject]@{ - Relative = [IO.Path]::GetRelativePath($Root, $file.FullName).Replace("\", "/") + Relative = $file.FullName.Substring($rootPrefix.Length).Replace("\", "/") File = $file } }