diff --git a/.jules/sentinel.md b/.jules/sentinel.md index 551e266..0804ae2 100644 --- a/.jules/sentinel.md +++ b/.jules/sentinel.md @@ -39,3 +39,8 @@ **Vulnerability:** Use of predictable, hardcoded temporary file paths and extraction directories in a shared `/tmp` directory. **Learning:** Using hardcoded paths for temporary files or directories (such as `TMP` and `EXTRACT_DIR` inside `/tmp` or `${PREFIX}/tmp`) makes the script vulnerable to symlink attacks, arbitrary file overwriting, and race conditions (CWE-377, CWE-59) by other local users on a shared system. **Prevention:** Always use `mktemp -d` to securely create a unique temporary directory with restricted `0700` permissions (readable/writable only by the owner), and place all temporary files and extraction directories within it. + +## 2026-07-31 - Environment Variable Hijacking and Arbitrary File Destruction via Trap Cleanup Logic +**Vulnerability:** Uninitialized critical variables in shell scripts (e.g., `ANTIGRAVITY_BAK`, `INSTALL_BIN_DIR`) can be hijacked from the parent environment, allowing users/attackers to manipulate execution flows. When coupled with script-level cleanup traps (like moving or deleting backup files on exit/cancel), uninitialized environment variables can lead to arbitrary file move or deletion operations (CWE-377, CWE-59, CWE-459). +**Learning:** Trap handlers in shell scripts run on any exit or cancellation. If the script fails or exits before variables are initialized inside the script body, pre-existing environment variables of the same name can control file operations inside the trap handler. +**Prevention:** Always explicitly initialize critical shell variables controlling backup paths, installation folders, or temporary locations at the very beginning of the script body. Additionally, validate that target variables are non-empty before executing state-altering commands like `mv` or `rm`. diff --git a/install.sh b/install.sh index 17c4fea..fcb46ef 100644 --- a/install.sh +++ b/install.sh @@ -2,6 +2,14 @@ # Antigravity CLI - Termux Native (Setup) set -Eeuo pipefail +# Security Enhancement (Sentinel): Initialize critical variables to prevent environment hijacking +# and arbitrary file deletion/move vulnerabilities (CWE-377, CWE-59, CWE-459). +ANTIGRAVITY_BAK="" +ANTIGRAVITY_VA39_BAK="" +INSTALL_BIN_DIR="" +SECURE_TMP_DIR="" +INSTALL_SUCCESS=0 + REPO="${ANTIGRAVITY_REPO:-wallentx/antigravity-cli-termux}" if [[ "$REPO" == -* || "$REPO" == *[!a-zA-Z0-9_./-]* ]]; then printf "[ERR] Invalid ANTIGRAVITY_REPO: contains unsafe characters or starts with a dash\n" >&2 @@ -62,12 +70,12 @@ mkdir -p "$SECURE_TMP_DIR" 2>/dev/null || true # ── Cleanup Hook ────────────────────────────────────────────────────────────── cleanup() { printf "\033[?25h" # Restore cursor if cancelled - [[ -d "$SECURE_TMP_DIR" ]] && rm -rf "$SECURE_TMP_DIR" + [[ -n "${SECURE_TMP_DIR:-}" && -d "$SECURE_TMP_DIR" ]] && rm -rf "$SECURE_TMP_DIR" if [[ "${INSTALL_SUCCESS:-0}" -ne 1 ]]; then - if [[ -n "${ANTIGRAVITY_BAK:-}" && -f "$ANTIGRAVITY_BAK" ]]; then + if [[ -n "${INSTALL_BIN_DIR:-}" && -n "${ANTIGRAVITY_BAK:-}" && -f "$ANTIGRAVITY_BAK" ]]; then mv -f "$ANTIGRAVITY_BAK" "$INSTALL_BIN_DIR/antigravity" || true fi - if [[ -n "${ANTIGRAVITY_VA39_BAK:-}" && -f "$ANTIGRAVITY_VA39_BAK" ]]; then + if [[ -n "${INSTALL_BIN_DIR:-}" && -n "${ANTIGRAVITY_VA39_BAK:-}" && -f "$ANTIGRAVITY_VA39_BAK" ]]; then mv -f "$ANTIGRAVITY_VA39_BAK" "$INSTALL_BIN_DIR/antigravity.va39" || true fi else