Skip to content

πŸ›‘οΈ Sentinel: [CRITICAL] Fix Insecure Temporary File Vulnerability#72

Open
kidchenko wants to merge 1 commit intomainfrom
sentinel-mktemp-vuln-fix-2902433558536863833
Open

πŸ›‘οΈ Sentinel: [CRITICAL] Fix Insecure Temporary File Vulnerability#72
kidchenko wants to merge 1 commit intomainfrom
sentinel-mktemp-vuln-fix-2902433558536863833

Conversation

@kidchenko
Copy link
Copy Markdown
Owner

@kidchenko kidchenko commented Mar 28, 2026

🚨 Severity: CRITICAL
πŸ’‘ Vulnerability: Insecure Temporary File (CWE-377). The installation script used a predictable path (/tmp/yq) to download an executable, which was subsequently moved with sudo privileges. A local attacker could pre-create this file or symlink to escalate privileges or overwrite arbitrary system files (TOCTOU attack).
🎯 Impact: Local Privilege Escalation (LPE) or arbitrary file overwrite by any local user during the execution of the apt.sh installation script.
πŸ”§ Fix: Replaced the hardcoded /tmp/yq path with a securely generated, restricted temporary directory using mktemp -d. Implemented an EXIT trap to guarantee cleanup of the temporary directory when the script finishes.
βœ… Verification: Verified that tools/os_installers/apt.sh securely creates a directory with mktemp -d and utilizes the EXIT trap. The updated syntax was successfully validated via shellcheck (run through ./build.sh lint).


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

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Enhanced installation script security by implementing automatic cleanup and using securely generated temporary directories instead of predictable fixed paths.
  • Documentation

    • Added documentation entry detailing a local privilege escalation vulnerability in installation scripts and recommended best practices for secure temporary directory handling.

Replaced the hardcoded, predictable temporary file path (`/tmp/yq`) in `tools/os_installers/apt.sh` with a securely generated temporary directory using `mktemp -d`. This prevents local privilege escalation (LPE) and symlink (TOCTOU) attacks when downloading and executing the `yq` binary with `sudo`. Also added a trap to ensure automatic cleanup upon script exit.

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 28, 2026

πŸ“ Walkthrough

Walkthrough

Added security documentation for a local privilege escalation vulnerability in installation scripts. Updated the apt installer to use securely generated temporary directories via mktemp -d instead of predictable fixed paths, with automatic cleanup via EXIT traps.

Changes

Cohort / File(s) Summary
Security Documentation
.jules/sentinel.md
Added entry documenting local privilege escalation vulnerability in temporary file handling and recommended mitigation using mktemp -d with EXIT traps.
Installation Script Security Fix
tools/os_installers/apt.sh
Updated yq download/install process to create temporary directory via mktemp -d instead of using fixed /tmp/yq path, with EXIT trap for cleanup.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A bunny hops with glee so bright,
No more /tmp paths left in sight!
With mktemp's charm and traps so neat,
This security fix makes our scripts quite sweet! ✨

πŸš₯ 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 an insecure temporary file vulnerability in installation scripts. It accurately reflects the security fix implemented across 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-mktemp-vuln-fix-2902433558536863833

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

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

207-211: Consider using similar secure temp directory pattern for other downloads.

The Go and lsd installers download files directly to the current working directory. While this is less risky than /tmp (since the current directory isn't world-writable), using the same mktemp -d pattern would provide defense-in-depth. This is a lower priority since these downloads don't use predictable paths in shared directories.

πŸ€– 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 207 - 211, Create and use a secure
temporary directory for the Go download instead of writing into the current
directory: call mktemp -d to produce a tempdir, download the
"go${GO_VERSION}.linux-amd64.tar.gz" into that tempdir (use the GO_VERSION
symbol to build the filename), run sudo tar -C /usr/local -xzf against the file
in the tempdir, then remove the tempdir (cleanup) after extraction; apply the
same mktemp -d pattern to the lsd installer download logic so both wget/rm
operations use an isolated temporary directory rather than the repository
working directory.
πŸ€– 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 first line to a top-level heading by replacing "##
2024-05-24 - [Local Privilege Escalation in Installation Scripts]" with "#
2024-05-24 - [Local Privilege Escalation in Installation Scripts]" and add a
blank line immediately after the heading; then wrap or reflow the subsequent
lines describing the vulnerability, learning, and prevention (the lines
mentioning "/tmp/yq", "mktemp -d", and the trap example) so no line exceeds 80
characters and ensure code snippets are fenced as a markdown code block.

---

Nitpick comments:
In `@tools/os_installers/apt.sh`:
- Around line 207-211: Create and use a secure temporary directory for the Go
download instead of writing into the current directory: call mktemp -d to
produce a tempdir, download the "go${GO_VERSION}.linux-amd64.tar.gz" into that
tempdir (use the GO_VERSION symbol to build the filename), run sudo tar -C
/usr/local -xzf against the file in the tempdir, then remove the tempdir
(cleanup) after extraction; apply the same mktemp -d pattern to the lsd
installer download logic so both wget/rm operations use an isolated temporary
directory rather than the repository working directory.
πŸͺ„ 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: a739cc88-41d8-493d-a116-44ce06b03667

πŸ“₯ Commits

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

πŸ“’ Files selected for processing (2)
  • .jules/sentinel.md
  • tools/os_installers/apt.sh

Comment on lines +1 to +4
## 2024-05-24 - [Local Privilege Escalation in Installation Scripts]
**Vulnerability:** Predictable temporary file paths (`/tmp/yq`) used during downloading executables, which were then processed with `sudo`.
**Learning:** Hardcoding shared temporary directories (`/tmp`) allows local attackers to pre-create files or symlinks (TOCTOU attacks). This is especially critical when combined with `sudo` execution.
**Prevention:** Always use securely generated, random temporary directories created by `mktemp -d` and paired with an `EXIT` trap for automated cleanup (e.g., `YQ_TMP_DIR=$(mktemp -d); trap "rm -rf '$YQ_TMP_DIR'" EXIT`).
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 markdown lint failures to pass CI.

The static analysis flagged several formatting issues:

  • Line 1: First line should be a top-level heading (# instead of ##)
  • Line 1: Missing blank line after heading
  • Lines 2-4: Line length exceeds 80 characters
πŸ“ Proposed fix for markdown formatting
-## 2024-05-24 - [Local Privilege Escalation in Installation Scripts]
-**Vulnerability:** Predictable temporary file paths (`/tmp/yq`) used during downloading executables, which were then processed with `sudo`.
-**Learning:** Hardcoding shared temporary directories (`/tmp`) allows local attackers to pre-create files or symlinks (TOCTOU attacks). This is especially critical when combined with `sudo` execution.
-**Prevention:** Always use securely generated, random temporary directories created by `mktemp -d` and paired with an `EXIT` trap for automated cleanup (e.g., `YQ_TMP_DIR=$(mktemp -d); trap "rm -rf '$YQ_TMP_DIR'" EXIT`).
+# Sentinel Security Notes
+
+## 2024-05-24 - Local Privilege Escalation in Installation Scripts
+
+**Vulnerability:** Predictable temporary file paths (`/tmp/yq`) used during
+downloading executables, which were then processed with `sudo`.
+
+**Learning:** Hardcoding shared temporary directories (`/tmp`) allows local
+attackers to pre-create files or symlinks (TOCTOU attacks). This is especially
+critical when combined with `sudo` execution.
+
+**Prevention:** Always use securely generated, random temporary directories
+created by `mktemp -d` and paired with an `EXIT` trap for automated cleanup:
+
+```bash
+YQ_TMP_DIR=$(mktemp -d)
+trap "rm -rf '$YQ_TMP_DIR'" EXIT
+```
πŸ“ 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 - [Local Privilege Escalation in Installation Scripts]
**Vulnerability:** Predictable temporary file paths (`/tmp/yq`) used during downloading executables, which were then processed with `sudo`.
**Learning:** Hardcoding shared temporary directories (`/tmp`) allows local attackers to pre-create files or symlinks (TOCTOU attacks). This is especially critical when combined with `sudo` execution.
**Prevention:** Always use securely generated, random temporary directories created by `mktemp -d` and paired with an `EXIT` trap for automated cleanup (e.g., `YQ_TMP_DIR=$(mktemp -d); trap "rm -rf '$YQ_TMP_DIR'" EXIT`).
# Sentinel Security Notes
## 2024-05-24 - Local Privilege Escalation in Installation Scripts
**Vulnerability:** Predictable temporary file paths (`/tmp/yq`) used during
downloading executables, which were then processed with `sudo`.
**Learning:** Hardcoding shared temporary directories (`/tmp`) allows local
attackers to pre-create files or symlinks (TOCTOU attacks). This is especially
critical when combined with `sudo` execution.
**Prevention:** Always use securely generated, random temporary directories
created by `mktemp -d` and paired with an `EXIT` trap for automated cleanup:
🧰 Tools
πŸͺ› GitHub Check: Lint Documentation

[failure] 4-4: Line length
.jules/sentinel.md:4:81 MD013/line-length Line length [Expected: 80; Actual: 220] 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: 200] 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: 139] 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 - [Local Privile..."] 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 - [Local Privilege Escalation in Installation 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, Change the first line to a top-level
heading by replacing "## 2024-05-24 - [Local Privilege Escalation in
Installation Scripts]" with "# 2024-05-24 - [Local Privilege Escalation in
Installation Scripts]" and add a blank line immediately after the heading; then
wrap or reflow the subsequent lines describing the vulnerability, learning, and
prevention (the lines mentioning "/tmp/yq", "mktemp -d", and the trap example)
so no line exceeds 80 characters and ensure code snippets are fenced as a
markdown code block.

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