T09 · Insecure Skill Coding Practices
- Location
scripts/bootstrap_restic_home.sh:97- Finding
Root Command Injection Through Shell-Sourced Configuration Values
- Content
View full analysis
/etc/restic-home.env </usr/local/bin/restic-home-backup.sh <<'EOF' #!/usr/bin/env bash set -euo pipefail source /etc/restic-home.env exec /usr/bin/restic backup "$BACKUP_SOURCE" --exclude-file "$EXCLUDES_FILE" EOF chmod 755 /usr/local/bin/restic-home-backup.sh cat >/usr/local/bin/restic-home-prune.sh <<'EOF' #!/usr/bin/env bash set -euo pipefail source /etc/restic-home.env exec /usr/bin/restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune EOF chmod 755 /usr/local/bin/restic-home-prune.sh cat >/usr/local/bin/restic-home-check.sh <<'EOF' #!/usr/bin/env bash set -euo pipefail source /etc/restic-home.env exec /usr/bin/restic check EOF chmod 755 /usr/local/bin/restic-home-check.sh ``` Repository initialization also directly sources the generated file: ```bash if [[ "$INIT_REPO" == "yes" ]]; then source /etc/restic-home.env if ! /usr/bin/restic snapshots >/dev/null 2>&1; then /usr/bin/restic init fi fi ``` ### Technical Analysis `REPO` and `PASS_FILE` are attacker-influenced command-line values. They are inserted into `/etc/restic-home.env` without shell escaping, quoting, newline rejection, or format validation. Becau ...[truncated 3160 chars]- Remediation
View remediation
/etc/restic-home.env ``` Strict validation should still be performed before serialization. 4. **Remove duplicate shell interpretation.** The systemd units already specify `EnvironmentFile=/etc/restic-home.env`; generated scripts should not source the same file. Prefer fixed executables that consume environment variables supplied by systemd. 5. **Reduce service privileges.** Run backup operations under a dedicated restricted account where repository and source permissions permit. If root access is required to read the entire home directory, add systemd hardening controls appropriate for restic, including: - `NoNewPrivileges=true` - `PrivateTmp=true` - `ProtectSystem=strict` - Explicit `ReadOnlyPaths=` for backup sources - Explicit `R ...[truncated 526 chars]
