diff --git a/.jules/sentinel.md b/.jules/sentinel.md new file mode 100644 index 0000000..5644c81 --- /dev/null +++ b/.jules/sentinel.md @@ -0,0 +1,4 @@ +## 2024-05-18 - [Predictable Temporary File Vulnerability] +**Vulnerability:** Predictable temporary file path `/tmp/yq` used in `tools/os_installers/apt.sh` to download and install `yq` as root. +**Learning:** Hardcoding a predictable file path in the world-writable directory `/tmp` could allow an attacker to launch a symlink attack or pre-create the file to gain privilege escalation when the script later runs `sudo mv /tmp/yq /usr/local/bin/yq`. This is especially dangerous in setup scripts that may be run by different users or multiple times. +**Prevention:** Always use `mktemp` (e.g., `mktemp -d`) to create secure, unpredictable temporary directories or files when downloading artifacts or storing intermediate data, especially if they are going to be accessed by `sudo` later. \ No newline at end of file diff --git a/tools/os_installers/apt.sh b/tools/os_installers/apt.sh index 156016b..15e9bfc 100644 --- a/tools/os_installers/apt.sh +++ b/tools/os_installers/apt.sh @@ -231,9 +231,11 @@ fi echo "Installing yq..." if ! command -v yq &> /dev/null; then YQ_VERSION="v4.44.6" - wget "https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64" -O /tmp/yq - sudo mv /tmp/yq /usr/local/bin/yq + TMP_DIR="$(mktemp -d)" + wget "https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64" -O "$TMP_DIR/yq" + sudo mv "$TMP_DIR/yq" /usr/local/bin/yq sudo chmod +x /usr/local/bin/yq + rm -rf "$TMP_DIR" fi # Install lsd (LSDeluxe)