Skip to content

🛡️ Sentinel: [CRITICAL] Fix insecure temporary file usage in apt installer#55

Open
kidchenko wants to merge 1 commit intomainfrom
sentinel-fix-apt-tmp-9798981713892148457
Open

🛡️ Sentinel: [CRITICAL] Fix insecure temporary file usage in apt installer#55
kidchenko wants to merge 1 commit intomainfrom
sentinel-fix-apt-tmp-9798981713892148457

Conversation

@kidchenko
Copy link
Owner

@kidchenko kidchenko commented Mar 11, 2026

The tools/os_installers/apt.sh script previously downloaded the yq binary to a hardcoded, predictable path (/tmp/yq) before using sudo to move it. This exposes the system to symlink attacks or arbitrary file overwrite vulnerabilities by local attackers.

This PR updates the script to securely generate a random temporary directory using mktemp -d. The yq binary is downloaded into this directory, moved securely, and the temporary directory is cleaned up afterward.

A corresponding journal entry detailing this vulnerability and its prevention was also added to .jules/sentinel.md.


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

Summary by CodeRabbit

  • Bug Fixes
    • Improved installer security by enhancing temporary file management during the installation process to prevent potential vulnerabilities.

…aller

The `tools/os_installers/apt.sh` script previously downloaded the `yq` binary to a hardcoded, predictable path (`/tmp/yq`) before using `sudo` to move it. This exposes the system to symlink attacks or arbitrary file overwrite vulnerabilities by local attackers.

This commit updates the script to securely generate a random temporary directory using `mktemp -d`. The `yq` binary is downloaded into this directory, moved securely, and the temporary directory is cleaned up afterward.

A corresponding journal entry detailing this vulnerability and its prevention was also added to `.jules/sentinel.md`.

Co-authored-by: kidchenko <5432753+kidchenko@users.noreply.github.com>
@google-labs-jules
Copy link
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

coderabbitai bot commented Mar 11, 2026

📝 Walkthrough

Walkthrough

A security vulnerability in an installer script is documented through a new advisory file, and the apt.sh installer script is refactored to use secure temporary directory creation (mktemp -d) instead of hardcoding /tmp/yq, eliminating potential symlink attack vectors during privileged operations.

Changes

Cohort / File(s) Summary
Security Documentation
.jules/sentinel.md
New file documenting an insecure temporary file creation vulnerability, detailing the risk of symlink attacks when hardcoding world-writable paths in privileged contexts and recommending mktemp -d for secure temporary directory generation.
Installer Script Refactor
tools/os_installers/apt.sh
Refactored yq binary installation to use securely generated temporary directory via mktemp -d instead of hardcoded /tmp/yq path, improving security posture against symlink attacks.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A symlink threat lurked in /tmp's embrace,
But now mktemp creates a safer place!
No more hardcoded paths in the sun,
Secure temp dirs—the fix is done! 🔐

🚥 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 directly addresses the main change: fixing insecure temporary file usage in the apt installer by using mktemp -d instead of hardcoded /tmp/yq.
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 (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sentinel-fix-apt-tmp-9798981713892148457

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

@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: 1

🧹 Nitpick comments (1)
tools/os_installers/apt.sh (1)

234-238: Consider adding trap-based cleanup for robustness.

If wget or sudo mv fails, the script exits (due to set -e on line 7) before reaching line 238, leaving the temporary directory behind. While not a security issue, this can accumulate leaked temp directories over time.

♻️ Proposed refactor using trap for cleanup
 if ! command -v yq &> /dev/null; then
     YQ_VERSION="v4.44.6"
     tmp_dir=$(mktemp -d)
+    trap 'rm -rf "$tmp_dir"' EXIT
     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"
+    trap - EXIT
+    rm -rf "$tmp_dir"
 fi

The trap ensures cleanup happens even if the script exits early due to errors.

🤖 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 234 - 238, The tmp_dir created by
mktemp can be left behind if wget or sudo mv fails; add a trap-based cleanup so
the temp dir is removed on exit. After creating tmp_dir with tmp_dir=$(mktemp
-d) (and before any failing commands like wget, sudo mv, chmod), install a trap
that runs rm -rf "$tmp_dir" on EXIT (and optionally ERR), ensure the trap only
runs when tmp_dir is non-empty, and if you need to keep the file on success,
explicitly remove tmp_dir and/or remove the trap after successful install;
reference tmp_dir, mktemp, wget, yq and the mv/chmod steps when making the
change.
🤖 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: Change the H2 heading "2024-05-15 - Insecure Temporary File
Creation in Installer Script" to a top-level H1 heading, add a blank line after
that heading, and reflow the following description lines (the vulnerability,
learning, and prevention bullets) to wrap at or below 80 characters so no lines
exceed the lint limit; ensure bullet markers and paragraph breaks are preserved
while keeping the same content.

---

Nitpick comments:
In `@tools/os_installers/apt.sh`:
- Around line 234-238: The tmp_dir created by mktemp can be left behind if wget
or sudo mv fails; add a trap-based cleanup so the temp dir is removed on exit.
After creating tmp_dir with tmp_dir=$(mktemp -d) (and before any failing
commands like wget, sudo mv, chmod), install a trap that runs rm -rf "$tmp_dir"
on EXIT (and optionally ERR), ensure the trap only runs when tmp_dir is
non-empty, and if you need to keep the file on success, explicitly remove
tmp_dir and/or remove the trap after successful install; reference tmp_dir,
mktemp, wget, yq and the mv/chmod steps when making the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2d47d2f6-7d47-41ad-afea-96055e3758f8

📥 Commits

Reviewing files that changed from the base of the PR and between cb5949a and 585d1bb.

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

Comment on lines +1 to +4
## 2024-05-15 - Insecure Temporary File Creation in Installer Script
**Vulnerability:** Hardcoded temporary file path `/tmp/yq` used before a `sudo mv` operation, which can lead to symlink attacks or arbitrary code execution by local attackers.
**Learning:** Hardcoding paths in world-writable directories like `/tmp` is dangerous, especially in scripts that escalate privileges (`sudo`). An attacker can exploit this predictable path before the script has a chance to secure it.
**Prevention:** Always use securely generated random directories (e.g., `mktemp -d`) for temporary files, especially in privileged operations.
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Address markdown linting violations.

The documentation linter is failing with multiple issues:

  • Line 1: First line should be a top-level heading (H1 #) instead of H2 (##)
  • Line 1: Missing blank line after heading
  • Lines 2-4: Lines exceed 80 characters
📝 Proposed fix for linting issues
-## 2024-05-15 - Insecure Temporary File Creation in Installer Script
-**Vulnerability:** Hardcoded temporary file path `/tmp/yq` used before a `sudo mv` operation, which can lead to symlink attacks or arbitrary code execution by local attackers.
-**Learning:** Hardcoding paths in world-writable directories like `/tmp` is dangerous, especially in scripts that escalate privileges (`sudo`). An attacker can exploit this predictable path before the script has a chance to secure it.
-**Prevention:** Always use securely generated random directories (e.g., `mktemp -d`) for temporary files, especially in privileged operations.
+# Sentinel Security Journal
+
+## 2024-05-15 - Insecure Temporary File Creation in Installer Script
+
+**Vulnerability:** Hardcoded temporary file path `/tmp/yq` used before a
+`sudo mv` operation, which can lead to symlink attacks or arbitrary code
+execution by local attackers.
+
+**Learning:** Hardcoding paths in world-writable directories like `/tmp` is
+dangerous, especially in scripts that escalate privileges (`sudo`). An
+attacker can exploit this predictable path before the script has a chance to
+secure it.
+
+**Prevention:** Always use securely generated random directories (e.g.,
+`mktemp -d`) for temporary files, especially in privileged operations.

This adds a top-level heading, blank lines around headings, and wraps long lines to meet the 80-character limit.

📝 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-15 - Insecure Temporary File Creation in Installer Script
**Vulnerability:** Hardcoded temporary file path `/tmp/yq` used before a `sudo mv` operation, which can lead to symlink attacks or arbitrary code execution by local attackers.
**Learning:** Hardcoding paths in world-writable directories like `/tmp` is dangerous, especially in scripts that escalate privileges (`sudo`). An attacker can exploit this predictable path before the script has a chance to secure it.
**Prevention:** Always use securely generated random directories (e.g., `mktemp -d`) for temporary files, especially in privileged operations.
# Sentinel Security Journal
## 2024-05-15 - Insecure Temporary File Creation in Installer Script
**Vulnerability:** Hardcoded temporary file path `/tmp/yq` used before a
`sudo mv` operation, which can lead to symlink attacks or arbitrary code
execution by local attackers.
**Learning:** Hardcoding paths in world-writable directories like `/tmp` is
dangerous, especially in scripts that escalate privileges (`sudo`). An
attacker can exploit this predictable path before the script has a chance to
secure it.
**Prevention:** Always use securely generated random directories (e.g.,
`mktemp -d`) for temporary files, especially in privileged operations.
🧰 Tools
🪛 GitHub Check: Lint Documentation

[failure] 4-4: Line length
.jules/sentinel.md:4:81 MD013/line-length Line length [Expected: 80; Actual: 142] 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: 234] 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: 175] 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-15 - Insecure Tempo..."] 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-15 - Insecure Temporary File Creation in Installer Script"] 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, Change the H2 heading "2024-05-15 -
Insecure Temporary File Creation in Installer Script" to a top-level H1 heading,
add a blank line after that heading, and reflow the following description lines
(the vulnerability, learning, and prevention bullets) to wrap at or below 80
characters so no lines exceed the lint limit; ensure bullet markers and
paragraph breaks are preserved while keeping the same content.

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