T09 · Insecure Skill Coding Practices
- Location
scripts/release.bat:24- Finding
Command Injection Through Unvalidated Arguments in the Windows Release Script
- Content
View full analysis
nul 2>&1 git checkout -b %RELEASE_BRANCH% ``` Feature branch arguments are similarly inserted into a batch loop and Git commands: ```bat set "FEATURE_BRANCHES=%~1" for %%i in (%FEATURE_BRANCHES%) do ( git rev-parse --verify %%i >nul 2>&1 if errorlevel 1 ( call :print_error "Branch %%i does not exist" exit /b 1 ) call :print_info "Merging branch: %%i" git merge --no-ff %%i -m "Merge feature branch: %%i" ) ``` Release operations reuse the same unvalidated value in merge, tag, push, and deletion commands: ```bat set "RELEASE_BRANCH=release/%VERSION%" git merge --no-ff %RELEASE_BRANCH% -m "Release version: %VERSION%" if "%CREATE_TAG%"=="true" ( git tag -a "v%VERSION%" -m "Release version: %VERSION%" git push origin "v%VERSION%" ) git branch -d %RELEASE_BRANCH% git push origin --delete %RELEASE_BRANCH% ``` ### Technical Analysis Windows batch files parse metacharacters such as `&`, `|`, `<`, `>`, `(`, and `)` as command syntax. The script accepts version and feature-branch values directly from command-line arguments and later expands them into unquoted command positions. Quoting the initial `set` assignment does not make la ...[truncated 1873 chars]- Remediation
View remediation
`, `^`, `%`, `!`, `(`, and `)`. 4. Do not construct a whitespace-separated branch list and reparse it with `for %%i in (...)`. 5. Avoid passing user-controlled expanded text through `call`. 6. Quote every Git argument and use `--` before positional refs where the Git subcommand supports it. 7. Check the exit status after every checkout, pull, merge, tag, push, and delete operation; stop immediately on failure. 8. Prefer implementing the release utility in a language that starts subprocesses with argument arrays rather than command strings, such as Python or PowerShell using structured process invocation. 9. Require an explicit preview and confirmation before pushing or deleting remote refs. 10. Add security tests covering spaces, wildcard characters, option-like values, and all Windows command metacharacters. ]]>
