T09 · Insecure Skill Coding Practices
- Location
scripts/run_on_m10.ps1:60- Finding
Remote Shell Argument Injection Through PipInstall
- Content
View full analysis
=!~ ]+$') { Write-Error "PipInstall must contain only package names and version specifiers." exit 1 } ``` ```powershell function Get-PipCommand([string]$package) { switch ($Mode) { "uv" { return "$UvPath pip install $package" } default { return "$PythonBin -m pip install $package" } } } ``` ```powershell if ($PipInstall) { Write-Host "Installing dependency: $PipInstall" if ($OfflinePipInstall) { $offlineInstaller = Join-Path $PSScriptRoot "install_m10_package_offline.ps1" $offlineArgs = @( "-ExecutionPolicy", "Bypass", "-File", $offlineInstaller, $PipInstall, "-M10Host", $M10Host, "-User", $User, "-Mode", $Mode, "-PythonBin", $PythonBin, "-UvPath", $UvPath ) powershell @offlineArgs if ($LASTEXITCODE -ne 0) { Write-Error "Offline dependency installation failed." exit $LASTEXITCODE } } else { $pipCmd = Get-PipCommand $PipInstall ssh -o StrictHostKeyChecking=accept-new "${User}@${M10Host}" $pipCmd ``` ### Technical Analysis The `PipInstall` validation expression permits spaces and the shell redirection characters `<` and `>`. The accepted value is interpolated without shell quoting into a command passed through SSH. OpenSSH invokes the supplied command through the remote user's shell. Consequently, characters such as `>` are interpreted as shell syntax rather than as part of a package specification. Spaces also allow additional pip arguments to be injected. The Bash implementation uses a materially stricter package validator and quotes the package va ...[truncated 1710 chars]- Remediation
View remediation
=!~]+[A-Za-z0-9_.-]+)?$') { throw "Package must be one PyPI package name with optional extras or one version specifier." } ``` 2. Do not concatenate user-controlled values into a remote shell command. Pass the package through a fixed remote helper that receives encoded or positional data and validates it again. 3. If a remote shell remains necessary, apply robust POSIX shell quoting to every dynamic argument. Validation should remain in place as defense in depth. 4. Do not allow arbitrary extra pip options through the package field. Expose any required option as a separately validated parameter. 5. Add negative tests for payloads containing spaces, redirection operators, option prefixes, quotes, command separators, substitutions, and newline characters. 6. Use a non-root deployment account and an isolated virtual environment wherever the board's operation permits it. ]]>
