Skip to content

Commit c9d0916

Browse files
Copilotbytemain
andauthored
Harden Windows hash quoting and CI failure check
Agent-Logs-Url: https://github.com/version-fox/vfox-python/sessions/5852e539-b06d-4c0c-b5d1-b981726a91d9 Co-authored-by: bytemain <13938334+bytemain@users.noreply.github.com>
1 parent f590d94 commit c9d0916

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

.github/workflows/vfox-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ jobs:
151151
Invoke-Expression "$(vfox activate pwsh)"
152152
$install_output = vfox install python@3.10.20 2>&1
153153
$install_output | Write-Output
154-
if ($LASTEXITCODE -ne 0 -or ($install_output -join "`n") -like "*failed to install python*") {
154+
if ($LASTEXITCODE -ne 0 -or ($install_output -join "`n") -ilike "*failed to install python*") {
155155
exit 1
156156
}
157157
vfox use -g python@3.10.20

lib/util.lua

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,21 @@ function useUvBuild()
228228
return value == "1" or value == "true" or value == "yes" or value == "on"
229229
end
230230

231+
local function containsTraversalSegment(value)
232+
local normalizedValue = string.gsub(value, "\\", "/")
233+
for segment in string.gmatch(normalizedValue, "[^/]+") do
234+
if segment == ".." then
235+
return true
236+
end
237+
end
238+
return false
239+
end
240+
231241
local function shellQuote(value)
232242
if string.find(value, "[\r\n%z]") then
233243
error("Path contains unsupported control character: " .. value)
234244
end
235-
if string.find(value, "%.%.%/") or string.find(value, "%.%.\\") then
245+
if containsTraversalSegment(value) then
236246
error("Path contains unsupported traversal segment: " .. value)
237247
end
238248

@@ -250,7 +260,7 @@ local function powershellQuote(value)
250260
if string.find(value, "[\r\n%z]") then
251261
error("Path contains unsupported control character: " .. value)
252262
end
253-
if string.find(value, "%.%.%/") or string.find(value, "%.%.\\") then
263+
if containsTraversalSegment(value) then
254264
error("Path contains unsupported traversal segment: " .. value)
255265
end
256266

@@ -469,6 +479,7 @@ local function verifyUvBuildArchive(path, sha256)
469479

470480
local status
471481
if RUNTIME.osType == "windows" or OS_TYPE == "windows" then
482+
-- shellQuote quotes for cmd.exe; powershellQuote quotes the archive path inside the PowerShell command.
472483
local command = "powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command " ..
473484
shellQuote("(Get-FileHash -LiteralPath " .. powershellQuote(path) .. " -Algorithm SHA256).Hash")
474485
local handle = io.popen(command)

0 commit comments

Comments
 (0)