From 4926cb0b847a4da7b8194cc9cdaec85ff999861b Mon Sep 17 00:00:00 2001 From: "MK (fengmk2)" Date: Thu, 8 Oct 2026 11:29:40 +0800 Subject: [PATCH] fix(azure): prevent setupRef script injection --- azure/setup-vp.yml | 4 ++-- src/azure/template.test.ts | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/azure/setup-vp.yml b/azure/setup-vp.yml index 76d8dfb..f301456 100644 --- a/azure/setup-vp.yml +++ b/azure/setup-vp.yml @@ -40,7 +40,7 @@ steps: - powershell: | $ErrorActionPreference = 'Stop' $bootstrap = Join-Path $env:AGENT_TEMPDIRECTORY 'setup-vp-azure-bootstrap.ps1' - $base = "https://raw.githubusercontent.com/voidzero-dev/setup-vp/${{ parameters.setupRef }}/azure" + $base = "https://raw.githubusercontent.com/voidzero-dev/setup-vp/$env:SETUP_VP_SETUP_REF/azure" Invoke-WebRequest -Uri "$base/bootstrap.ps1" -OutFile $bootstrap -TimeoutSec 60 & $bootstrap condition: and(succeeded(), eq(variables['Agent.OS'], 'Windows_NT')) @@ -60,7 +60,7 @@ steps: - bash: | set -euo pipefail bootstrap="$(Agent.TempDirectory)/setup-vp-azure-bootstrap.sh" - base="https://raw.githubusercontent.com/voidzero-dev/setup-vp/${{ parameters.setupRef }}/azure" + base="https://raw.githubusercontent.com/voidzero-dev/setup-vp/${SETUP_VP_SETUP_REF}/azure" curl -fsSL --connect-timeout 5 --max-time 60 "$base/bootstrap.sh" -o "$bootstrap" chmod +x "$bootstrap" bash "$bootstrap" diff --git a/src/azure/template.test.ts b/src/azure/template.test.ts index 409d6fe..060a7f3 100644 --- a/src/azure/template.test.ts +++ b/src/azure/template.test.ts @@ -53,6 +53,15 @@ describe("azure/setup-vp.yml", () => { expect(template).toContain("bootstrap.ps1"); }); + it("does not interpolate setupRef into executable script source", () => { + expect(template).not.toContain("setup-vp/${{ parameters.setupRef }}/azure"); + expect(template).toContain("setup-vp/$env:SETUP_VP_SETUP_REF/azure"); + expect(template).toContain("setup-vp/${SETUP_VP_SETUP_REF}/azure"); + expect( + template.match(/SETUP_VP_SETUP_REF: \$\{\{ parameters\.setupRef \}\}/g) ?? [], + ).toHaveLength(2); + }); + it("selects the agent shell at runtime", () => { expect(template).not.toContain("${{ if eq(variables['Agent.OS'], 'Windows_NT') }}"); expect(template).not.toContain("${{ if ne(variables['Agent.OS'], 'Windows_NT') }}");