Windows script placement should use non-expandable here-string (`@'...'@`) to match Linux heredoc defense
Problem
In pkg/pod/script.go, the place-scripts init container builds differently for Linux vs Windows:
Linux (safe): single-quoted heredoc prevents shell expansion
initContainer.Args[1] += fmt.Sprintf(`scriptfile="%s"
touch ${scriptfile} && chmod +x ${scriptfile}
cat > ${scriptfile} << '%s'
%s
%s
`, scriptFile, heredoc, script, heredoc)Windows (gap): expandable here-string allows termination via "@
initContainer.Args[1] += fmt.Sprintf(`@"
%s
"@ | Out-File -FilePath %s
`, script, scriptFile)If a script contains "@ on its own line (e.g., from $(params.x) substitution), it terminates the here-string early and the remaining content becomes PowerShell commands in the init container.
Proposed Fix
Switch to non-expandable here-string:
initContainer.Args[1] += fmt.Sprintf(`@'
%s
'@ | Out-File -FilePath %s
`, script, scriptFile)@'...'@ in PowerShell is the equivalent of single-quoted heredoc in shell — no variable expansion, no special character interpretation. The only sequence that terminates it is '@ on its own line, which is far less likely to appear in script content.
Note
This is defense-in-depth. The root cause is that $(params.x) is raw string interpolation by design. Users should pass untrusted values through environment variables rather than direct param substitution in scripts. This applies to both Linux and Windows.
Context
Reported via a security advisory (closed as not a security vulnerability — known design limitation, same trust domain, same class as Linux script injection).
/kind bug /area api
Source: tektoncd/pipeline