Skip to content

Commit cfa7d5c

Browse files
committed
Add an additional safety check to prevent removal of paths outside the repository root
1 parent 1c5ebde commit cfa7d5c

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

build/Build-MaesterModule.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ if ($ResolvedOutput -ieq $DriveRoot) {
6868
if ($ResolvedOutput -ieq $RepoRoot.TrimEnd('\', '/')) {
6969
throw "Refusing to use OutputRoot '$OutputRoot' because it resolves to the repository root: '$RepoRoot'."
7070
}
71+
$RepoPath = $RepoRoot.TrimEnd('\', '/')
72+
if (-not $ResolvedOutput.StartsWith($RepoPath + [System.IO.Path]::DirectorySeparatorChar, [System.StringComparison]::OrdinalIgnoreCase)) {
73+
throw "Refusing to use OutputRoot '$OutputRoot' because it is outside the repository root '$RepoRoot'."
74+
}
7175

7276
if (Test-Path -LiteralPath $OutputRoot) {
7377
Remove-Item -LiteralPath $OutputRoot -Recurse -Force

0 commit comments

Comments
 (0)