This review analyzes the shell scripts in the vmware-samples/tmc-migration-scripts repository, which contains 70+ scripts for migrating resources from VMware Tanzu Mission Control (TMC) SaaS to Self-Managed deployments. The analysis identified several critical security vulnerabilities, potential data loss scenarios, and reliability issues that should be addressed before production use.
Risk Level: HIGH - Multiple critical issues that could result in data loss or security compromise.
Location: utils/common.sh:41
rm -rf $DATA_DIR/* # If $DATA_DIR is empty, this becomes "rm -rf /*"Risk: Potential catastrophic data loss
Fix: Use rm -rf "${DATA_DIR:?}/"*
Location: utils/common.sh:46
trap "on_exit $msg" EXIT # $msg could contain malicious commandsFix: Use single quotes: trap 'on_exit "$msg"' EXIT
Location: 059-admin-settings-import.sh:31-35
sourceRidParts=($sourceRid)
filename="${sourceRidParts[6]}" # No bounds checkingFix: Validate array length before accessing indices
Locations: Throughout codebase (100+ instances)
if [ -z $name ]; then # Should be: if [ -z "$name" ]; then- Critical: Complete filesystem deletion possible
- High: Migration data corruption from array bounds violations
- Medium: Wrong resources affected by word splitting
- High: Arbitrary command execution through trap handlers
- Medium: Information disclosure through verbose errors
- Medium: Race conditions in credential handling
- High: Silent failures with unclear error messages
- Medium: Inconsistent behavior across environments
- Medium: Difficult troubleshooting and debugging
- Missing shebangs in some scripts
- Inconsistent error handling (
set -eusage) - Use of deprecated backticks instead of
$() - Unsafe glob patterns and file operations
- Command injection through unquoted trap handlers
- Unsafe file deletion patterns
- Missing input validation on critical paths
- Uncontrolled variable expansion
- Array access without bounds checking
- Race conditions with fixed sleep intervals
- Missing timeout handling for API calls
- Inadequate error handling and logging
- Quote all variable expansions to prevent word splitting
- Fix unsafe
rm -rfusage to prevent data loss - Add array bounds validation before accessing indices
- Fix command injection in trap handlers
- Standardize error handling across all scripts
- Add comprehensive input validation
- Implement proper API timeout handling
- Add missing shebangs and fix syntax issues
- Run shellcheck in CI/CD pipeline
- Add comprehensive testing for edge cases
- Improve documentation and error messages
- Standardize code style and patterns
Shellcheck analysis revealed:
- 150+ warnings/errors across utility and main scripts
- 50+ unquoted variable expansions (SC2086)
- Multiple command injection risks (SC2046, SC2064)
- Unsafe file operations (SC2115, SC2035)
- Logic and control flow issues (SC2181, SC2164)
- Static Analysis: Run shellcheck on all scripts
- Security Testing: Test with malicious inputs
- Integration Testing: Test end-to-end scenarios
- Recovery Testing: Test failure and rollback scenarios
- Performance Testing: Test with large datasets
rm -rf $DATA_DIR/*
trap "on_exit $msg" EXIT
if [ -z $name ]; then
sourceRidParts=($sourceRid)rm -rf "${DATA_DIR:?}/"*
trap 'on_exit "$msg"' EXIT
if [ -z "${name:-}" ]; then
IFS=':' read -ra sourceRidParts <<< "$sourceRid"The TMC migration scripts provide valuable functionality but contain critical security and safety issues that must be addressed before production use. The most serious risks involve potential data loss and command injection vulnerabilities.
Recommendation: Do not use these scripts in production until critical issues are resolved.
This review was conducted using static analysis tools and manual code inspection. For complete security assurance, dynamic testing and penetration testing are recommended.