Skip to content

🛡️ Sentinel: [HIGH] Fix insecure temporary file handling in apt installer#71

Open
kidchenko wants to merge 1 commit intomainfrom
sentinel/fix-insecure-tmp-files-28599786978884121
Open

🛡️ Sentinel: [HIGH] Fix insecure temporary file handling in apt installer#71
kidchenko wants to merge 1 commit intomainfrom
sentinel/fix-insecure-tmp-files-28599786978884121

Conversation

@kidchenko
Copy link
Copy Markdown
Owner

@kidchenko kidchenko commented Mar 27, 2026

🚨 Severity: HIGH
💡 Vulnerability: The script tools/os_installers/apt.sh downloaded executables or installation artifacts directly into the current working directory or predictable temporary locations (e.g., /tmp/yq), and then moved or executed them with elevated (sudo) privileges. This exposed the installation process to local privilege escalation, symlink attacks, and unintentional file overwriting.
🎯 Impact: A local attacker could pre-create files or symlinks at predictable paths (like /tmp/yq), allowing them to overwrite critical system files or execute arbitrary code with elevated privileges during the installation process.
🔧 Fix: Refactored the script to create a secure, randomized temporary directory using mktemp -d and paired it with an EXIT trap for automatic cleanup. Updated the installation commands for Go, yq, lsd, and Composer to download artifacts into this isolated directory.
Verification: Run ./build.sh to ensure there are no syntax errors. Manually verify tools/os_installers/apt.sh to ensure it runs correctly and downloads files to a temporary directory before moving them to their final destination. Review .jules/sentinel.md to see the documented vulnerability.


PR created automatically by Jules for task 28599786978884121 started by @kidchenko

Summary by CodeRabbit

Release Notes

  • Security

    • Enhanced APT installer with secure temporary directory creation and automatic cleanup for installation artifacts, reducing installation-related security risks.
  • Documentation

    • Added documentation on temporary file security vulnerabilities and mitigation strategies in installer scripts, including best practices for secure directory management.

Updated `tools/os_installers/apt.sh` to download executables and
installation artifacts into a secure temporary directory generated by
`mktemp -d` rather than the current working directory or predictable
paths like `/tmp/`. Included an EXIT trap to ensure the secure cleanup
of these files. Also documented this security finding in
`.jules/sentinel.md` as required by the Sentinel process.

Co-authored-by: kidchenko <5432753+kidchenko@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 27, 2026

📝 Walkthrough

Walkthrough

A vulnerability report documenting insecure temporary file handling in installer scripts was added to the documentation. The apt.sh installer script was subsequently modified to implement the recommended mitigation: using mktemp -d to create randomized temporary directories and an exit trap for automatic cleanup, replacing previous direct usage of /tmp and current working directories.

Changes

Cohort / File(s) Summary
Security documentation
.jules/sentinel.md
Added vulnerability report detailing insecure temporary file handling patterns in installer scripts and mitigation approach using secure temporary directory creation.
Installer script refactoring
tools/os_installers/apt.sh
Implemented secure temporary directory handling: introduced TMP_DIR=$(mktemp -d) with an EXIT trap for cleanup. Updated Go, yq, lsd, and Composer installation flows to download artifacts into TMP_DIR instead of /tmp or current directory, removing previous manual cleanup statements.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A warren of scripts, once loose with their files,
Now nestle in folders that vanish with style,
With mktemp and trap, the cleanup's a dream,
Security blooms in our shell-scripting scheme! 🌱✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: fixing insecure temporary file handling in the apt installer script. It directly matches the vulnerability addressed and the refactoring performed in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sentinel/fix-insecure-tmp-files-28599786978884121

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.jules/sentinel.md:
- Around line 1-4: Add a file-level H1 at the top of .jules/sentinel.md, ensure
there is a blank line above and below the entry heading "2024-05-24 - [Insecure
Temporary File Handling in Installer Scripts]" to satisfy MD022, and reflow/wrap
the paragraph text (the Vulnerability, Learning, and Prevention lines) to a
reasonable line length to fix MD013; keep the existing heading text and content
but split long lines into wrapped paragraphs and ensure one blank line separates
headings from content to resolve MD041/MD022/MD013 together.

In `@tools/os_installers/apt.sh`:
- Around line 257-265: The Composer integrity branch currently only logs an
error and continues; change the else branch that handles EXPECTED_CHECKSUM vs
ACTUAL_CHECKSUM so it fails closed by exiting with a non-zero status (e.g., call
exit 1) after printing the error; update the block around EXPECTED_CHECKSUM,
ACTUAL_CHECKSUM and the sudo php install step (the composer installer
checksum/installation section) to ensure the script stops when the checksum
mismatches rather than proceeding.
- Around line 212-214: The installers in tools/os_installers/apt.sh currently
wget binaries and run privileged install steps (e.g. the Go download using
GO_VERSION and TMP_DIR followed by sudo tar -C /usr/local, plus the yq and lsd
download/install sections) without verifying integrity; update each installer to
fetch the upstream checksum/signature asset for the pinned release, verify the
downloaded artifact (e.g. compute sha256sum and compare against upstream
checksum or verify signature with GPG) before performing any sudo actions, and
abort with a clear error on mismatch; for Go use the go.dev SHA256 API for
GO_VERSION and verify "$TMP_DIR/go${GO_VERSION}.linux-amd64.tar.gz" before sudo
tar, for yq use the release checksums/checksums-bsd asset and verify the binary
before moving to /usr/local/bin, and for lsd fetch the GitHub release
checksum/signature and verify the .deb before running dpkg.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 06f46677-3c0b-4d5f-aec2-4ffb9748c415

📥 Commits

Reviewing files that changed from the base of the PR and between eb5ca40 and 624bde1.

📒 Files selected for processing (2)
  • .jules/sentinel.md
  • tools/os_installers/apt.sh

Comment thread .jules/sentinel.md
Comment on lines +1 to +4
## 2024-05-24 - [Insecure Temporary File Handling in Installer Scripts]
**Vulnerability:** Scripts like `tools/os_installers/apt.sh` downloaded executables or installation artifacts directly into the current working directory or predictable temporary locations (e.g., `/tmp/yq`), and then moved or executed them with elevated (`sudo`) privileges.
**Learning:** This exposes the installation process to local privilege escalation, symlink attacks, and unintentional file overwriting. Downloading to predictable locations allows a local attacker to pre-create files or symlinks at those paths.
**Prevention:** Always use securely generated random directories (e.g., `mktemp -d`) for downloading and processing temporary files during installation, especially when elevated privileges are involved. Pair `mktemp -d` with a `trap 'rm -rf "$TMP_DIR"' EXIT` to ensure automatic cleanup. No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix the markdownlint failures in this new note.

This entry currently trips MD041, MD022, and MD013, so the docs lint job stays red. Add a file-level H1, blank lines around the entry heading, and wrap the paragraphs.

💡 Suggested fix
+# Sentinel learnings
+
 ## 2024-05-24 - [Insecure Temporary File Handling in Installer Scripts]
-**Vulnerability:** Scripts like `tools/os_installers/apt.sh` downloaded executables or installation artifacts directly into the current working directory or predictable temporary locations (e.g., `/tmp/yq`), and then moved or executed them with elevated (`sudo`) privileges.
-**Learning:** This exposes the installation process to local privilege escalation, symlink attacks, and unintentional file overwriting. Downloading to predictable locations allows a local attacker to pre-create files or symlinks at those paths.
-**Prevention:** Always use securely generated random directories (e.g., `mktemp -d`) for downloading and processing temporary files during installation, especially when elevated privileges are involved. Pair `mktemp -d` with a `trap 'rm -rf "$TMP_DIR"' EXIT` to ensure automatic cleanup.
+
+**Vulnerability:** Scripts like `tools/os_installers/apt.sh` downloaded
+executables or installation artifacts directly into the current working
+directory or predictable temporary locations (e.g., `/tmp/yq`), and then moved
+or executed them with elevated (`sudo`) privileges.
+
+**Learning:** This exposes the installation process to local privilege
+escalation, symlink attacks, and unintentional file overwriting. Downloading to
+predictable locations allows a local attacker to pre-create files or symlinks at
+those paths.
+
+**Prevention:** Always use securely generated random directories (e.g.,
+`mktemp -d`) for downloading and processing temporary files during installation,
+especially when elevated privileges are involved. Pair `mktemp -d` with a
+`trap 'rm -rf "$TMP_DIR"' EXIT` to ensure automatic cleanup.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
## 2024-05-24 - [Insecure Temporary File Handling in Installer Scripts]
**Vulnerability:** Scripts like `tools/os_installers/apt.sh` downloaded executables or installation artifacts directly into the current working directory or predictable temporary locations (e.g., `/tmp/yq`), and then moved or executed them with elevated (`sudo`) privileges.
**Learning:** This exposes the installation process to local privilege escalation, symlink attacks, and unintentional file overwriting. Downloading to predictable locations allows a local attacker to pre-create files or symlinks at those paths.
**Prevention:** Always use securely generated random directories (e.g., `mktemp -d`) for downloading and processing temporary files during installation, especially when elevated privileges are involved. Pair `mktemp -d` with a `trap 'rm -rf "$TMP_DIR"' EXIT` to ensure automatic cleanup.
# Sentinel learnings
## 2024-05-24 - [Insecure Temporary File Handling in Installer Scripts]
**Vulnerability:** Scripts like `tools/os_installers/apt.sh` downloaded
executables or installation artifacts directly into the current working
directory or predictable temporary locations (e.g., `/tmp/yq`), and then moved
or executed them with elevated (`sudo`) privileges.
**Learning:** This exposes the installation process to local privilege
escalation, symlink attacks, and unintentional file overwriting. Downloading to
predictable locations allows a local attacker to pre-create files or symlinks at
those paths.
**Prevention:** Always use securely generated random directories (e.g.,
`mktemp -d`) for downloading and processing temporary files during installation,
especially when elevated privileges are involved. Pair `mktemp -d` with a
`trap 'rm -rf "$TMP_DIR"' EXIT` to ensure automatic cleanup.
🧰 Tools
🪛 GitHub Check: Lint Documentation

[failure] 4-4: Line length
.jules/sentinel.md:4:81 MD013/line-length Line length [Expected: 80; Actual: 287] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md013.md


[failure] 3-3: Line length
.jules/sentinel.md:3:81 MD013/line-length Line length [Expected: 80; Actual: 244] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md013.md


[failure] 2-2: Line length
.jules/sentinel.md:2:81 MD013/line-length Line length [Expected: 80; Actual: 274] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md013.md


[failure] 1-1: First line in a file should be a top-level heading
.jules/sentinel.md:1 MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "## 2024-05-24 - [Insecure Temp..."] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md041.md


[failure] 1-1: Headings should be surrounded by blank lines
.jules/sentinel.md:1 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## 2024-05-24 - [Insecure Temporary File Handling in Installer Scripts]"] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md022.md

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.jules/sentinel.md around lines 1 - 4, Add a file-level H1 at the top of
.jules/sentinel.md, ensure there is a blank line above and below the entry
heading "2024-05-24 - [Insecure Temporary File Handling in Installer Scripts]"
to satisfy MD022, and reflow/wrap the paragraph text (the Vulnerability,
Learning, and Prevention lines) to a reasonable line length to fix MD013; keep
the existing heading text and content but split long lines into wrapped
paragraphs and ensure one blank line separates headings from content to resolve
MD041/MD022/MD013 together.

Comment on lines +212 to +214
wget "https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz" -O "$TMP_DIR/go${GO_VERSION}.linux-amd64.tar.gz"
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf "go${GO_VERSION}.linux-amd64.tar.gz"
rm "go${GO_VERSION}.linux-amd64.tar.gz"
sudo tar -C /usr/local -xzf "$TMP_DIR/go${GO_VERSION}.linux-amd64.tar.gz"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Go 1.23.4:"
curl -fsSL 'https://go.dev/dl/?mode=json&include=all' \
  | jq -r '.[] | select(.version=="go1.23.4") | .files[] | select(.filename=="go1.23.4.linux-amd64.tar.gz") | {filename, sha256}'

echo
echo "yq v4.44.6 assets:"
curl -fsSL 'https://api.github.com/repos/mikefarah/yq/releases/tags/v4.44.6' \
  | jq -r '.assets[]?.name'

echo
echo "lsd v1.1.5 assets:"
curl -fsSL 'https://api.github.com/repos/lsd-rs/lsd/releases/tags/v1.1.5' \
  | jq -r '.assets[]?.name'

Repository: kidchenko/dotfiles

Length of output: 2024


🏁 Script executed:

# Find the file and check its size first
wc -l tools/os_installers/apt.sh

Repository: kidchenko/dotfiles

Length of output: 92


🏁 Script executed:

# Read the specific sections mentioned in the review
echo "=== Lines 200-220 (context for 212-214) ==="
sed -n '200,220p' tools/os_installers/apt.sh

echo
echo "=== Lines 225-255 (context for 237-239 and 246-247) ==="
sed -n '225,255p' tools/os_installers/apt.sh

Repository: kidchenko/dotfiles

Length of output: 1989


Add checksum/signature verification before executing privileged operations.

All three tools download binaries from the network and immediately execute them as root without verification:

  • Go 1.23.4: downloads and extracts as root (lines 212-214)
  • yq v4.44.6: downloads and installs to /usr/local/bin as root (lines 237-239)
  • lsd 1.1.5: downloads and installs with dpkg as root (lines 246-247)

While the temp-dir fix mitigates symlink/path attacks, these installers remain vulnerable to network tampering (MITM). Upstream provides verification data for all pinned versions:

  • Go: SHA256 checksums via go.dev API
  • yq: checksums and checksums-bsd files in release assets
  • lsd: standard GitHub release assets

Implement checksum verification (or use signed package sources where available) before each privileged step.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tools/os_installers/apt.sh` around lines 212 - 214, The installers in
tools/os_installers/apt.sh currently wget binaries and run privileged install
steps (e.g. the Go download using GO_VERSION and TMP_DIR followed by sudo tar -C
/usr/local, plus the yq and lsd download/install sections) without verifying
integrity; update each installer to fetch the upstream checksum/signature asset
for the pinned release, verify the downloaded artifact (e.g. compute sha256sum
and compare against upstream checksum or verify signature with GPG) before
performing any sudo actions, and abort with a clear error on mismatch; for Go
use the go.dev SHA256 API for GO_VERSION and verify
"$TMP_DIR/go${GO_VERSION}.linux-amd64.tar.gz" before sudo tar, for yq use the
release checksums/checksums-bsd asset and verify the binary before moving to
/usr/local/bin, and for lsd fetch the GitHub release checksum/signature and
verify the .deb before running dpkg.

Comment on lines 257 to 265
EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"
php -r "copy('https://getcomposer.org/installer', '$TMP_DIR/composer-setup.php');"
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', '$TMP_DIR/composer-setup.php');")"

if [ "$EXPECTED_CHECKSUM" = "$ACTUAL_CHECKSUM" ]; then
sudo php composer-setup.php --quiet --install-dir=/usr/local/bin --filename=composer
rm composer-setup.php
sudo php "$TMP_DIR/composer-setup.php" --quiet --install-dir=/usr/local/bin --filename=composer
else
>&2 echo 'ERROR: Invalid installer checksum for Composer'
rm composer-setup.php
fi
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Make the Composer integrity check fail closed.

If the checksum mismatches, this only logs and continues, so the script can still reach the final success banner with Composer silently skipped. Treat that branch as fatal.

💡 Suggested fix
     if [ "$EXPECTED_CHECKSUM" = "$ACTUAL_CHECKSUM" ]; then
         sudo php "$TMP_DIR/composer-setup.php" --quiet --install-dir=/usr/local/bin --filename=composer
     else
         >&2 echo 'ERROR: Invalid installer checksum for Composer'
+        exit 1
     fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"
php -r "copy('https://getcomposer.org/installer', '$TMP_DIR/composer-setup.php');"
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', '$TMP_DIR/composer-setup.php');")"
if [ "$EXPECTED_CHECKSUM" = "$ACTUAL_CHECKSUM" ]; then
sudo php composer-setup.php --quiet --install-dir=/usr/local/bin --filename=composer
rm composer-setup.php
sudo php "$TMP_DIR/composer-setup.php" --quiet --install-dir=/usr/local/bin --filename=composer
else
>&2 echo 'ERROR: Invalid installer checksum for Composer'
rm composer-setup.php
fi
EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"
php -r "copy('https://getcomposer.org/installer', '$TMP_DIR/composer-setup.php');"
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', '$TMP_DIR/composer-setup.php');")"
if [ "$EXPECTED_CHECKSUM" = "$ACTUAL_CHECKSUM" ]; then
sudo php "$TMP_DIR/composer-setup.php" --quiet --install-dir=/usr/local/bin --filename=composer
else
>&2 echo 'ERROR: Invalid installer checksum for Composer'
exit 1
fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tools/os_installers/apt.sh` around lines 257 - 265, The Composer integrity
branch currently only logs an error and continues; change the else branch that
handles EXPECTED_CHECKSUM vs ACTUAL_CHECKSUM so it fails closed by exiting with
a non-zero status (e.g., call exit 1) after printing the error; update the block
around EXPECTED_CHECKSUM, ACTUAL_CHECKSUM and the sudo php install step (the
composer installer checksum/installation section) to ensure the script stops
when the checksum mismatches rather than proceeding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant