Skip to content

πŸ›‘οΈ Sentinel: [CRITICAL] Fix predictable and insecure temporary file paths#67

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

πŸ›‘οΈ Sentinel: [CRITICAL] Fix predictable and insecure temporary file paths#67
kidchenko wants to merge 1 commit intomainfrom
sentinel-fix-apt-tmp-vuln-8874931659919427575

Conversation

@kidchenko
Copy link
Copy Markdown
Owner

@kidchenko kidchenko commented Mar 23, 2026

🚨 Severity: CRITICAL
πŸ’‘ Vulnerability: Installation scripts downloaded files to predictable locations (/tmp/yq) or the current working directory, which risks symlink attacks and overwriting existing files, especially when running as sudo.
🎯 Impact: Local privilege escalation. A malicious user could create a symlink at /tmp/yq pointing to a critical system file, which sudo mv would then overwrite. Downloading to the current directory risks overwriting attacker-controlled files.
πŸ”§ Fix: Used mktemp -d to create a securely generated temporary directory with restrictive permissions (0700) to safely download, extract, and move artifacts.
βœ… Verification: Ran ./build.sh to ensure script validation passes. Visually inspected tools/os_installers/apt.sh to confirm proper usage of mktemp -d and subsequent removal.


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

Summary by CodeRabbit

  • Bug Fixes

    • Resolved critical security vulnerability in installer scripts for Go, yq, lsd, and Composer by implementing secure temporary file handling.
    • Improved artifact staging mechanisms to mitigate risks during elevated-privilege installation processes.
  • Documentation

    • Added security advisory documenting critical installation process improvements.

…aths

Installation scripts (tools/os_installers/apt.sh) downloaded files to predictable locations (/tmp/yq) or the current working directory, which risks symlink attacks and overwriting existing files, especially when running as `sudo`. Updated logic to use securely generated temporary directories (`mktemp -d`).

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

πŸ“ Walkthrough

Walkthrough

The PR addresses a security vulnerability in the installation script by replacing fixed temporary file paths with securely generated random directories. Downloads for Go, yq, lsd, and Composer dependencies are now staged in temporary directories created via mktemp -d, with cleanup after installation.

Changes

Cohort / File(s) Summary
Security Documentation
.jules/sentinel.md
Added entry documenting critical security issue with predictable temporary file paths in installation scripts and guidance for remediation using mktemp -d.
Installation Script Security Fix
tools/os_installers/apt.sh
Modified installer to use securely generated temporary directories (TMP_DIR=$(mktemp -d)) for staging downloads instead of fixed paths; applied consistently across Go, yq, lsd, and Composer installation blocks with unconditional cleanup.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A bunny hops through /tmp with care,
No symlinks lurking in the air!
With mktemp -d secure and tight,
Installations staged just right.
Cleanup done, the temp files gone,
Safe installations march along! πŸ₯•

πŸš₯ 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 security fix: using mktemp for secure temporary directories instead of predictable paths, which directly matches the core changes in apt.sh and the security documentation.
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-apt-tmp-vuln-8874931659919427575

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)

259-270: Consider using a trap to ensure temp directory cleanup on error.

The cleanup on line 269 runs unconditionally at block end, which is good. However, if an error occurs between mktemp -d and rm -rf (e.g., checksum mismatch followed by set -e exit on a later command), the temp directory may remain. This is a minor robustness improvement.

♻️ Optional: Use trap for guaranteed cleanup
 if ! command -v composer &> /dev/null; then
     TMP_DIR=$(mktemp -d)
+    trap 'rm -rf "${TMP_DIR}"' EXIT
     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'
     fi
     rm -rf "${TMP_DIR}"
+    trap - EXIT
 fi

Note: Since set -e is enabled and the current cleanup happens unconditionally before the fi, this is only a concern if future modifications introduce early exits. The current implementation is acceptable.

πŸ€– 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 259 - 270, Wrap TMP_DIR creation and
removal with a trap so the temporary directory created by TMP_DIR=$(mktemp -d)
is removed even if the script exits early; specifically, after TMP_DIR is
assigned (and before downloading composer-setup.php with php -r), register a
trap that runs rm -rf "${TMP_DIR}" on EXIT, and ensure any later explicit rm -rf
"${TMP_DIR}" is safe (no-op if already removed) and the trap is cleaned up if
necessary; this ensures the composer-setup.php download and the checksum check
(ACTUAL_CHECKSUM/hash_file and EXPECTED_CHECKSUM) cannot leak the temp dir on
errors.
πŸ€– 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 top-level heading to a single '#' in
.jules/sentinel.md, add a blank line immediately after that heading, and
wrap/reflow the long lines in the body (the lines mentioning the vulnerability,
learning, and prevention) so no line exceeds 80 characters; ensure the three
sections ("Vulnerability:", "Learning:", "Prevention:") remain intact and
readable after rewrapping.

---

Nitpick comments:
In `@tools/os_installers/apt.sh`:
- Around line 259-270: Wrap TMP_DIR creation and removal with a trap so the
temporary directory created by TMP_DIR=$(mktemp -d) is removed even if the
script exits early; specifically, after TMP_DIR is assigned (and before
downloading composer-setup.php with php -r), register a trap that runs rm -rf
"${TMP_DIR}" on EXIT, and ensure any later explicit rm -rf "${TMP_DIR}" is safe
(no-op if already removed) and the trap is cleaned up if necessary; this ensures
the composer-setup.php download and the checksum check
(ACTUAL_CHECKSUM/hash_file and EXPECTED_CHECKSUM) cannot leak the temp dir on
errors.

ℹ️ Review info
βš™οΈ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7e46e4e9-cb51-4b27-ba78-97081cbaca14

πŸ“₯ Commits

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

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

Comment on lines +1 to +4
## 2024-05-24 - [CRITICAL] Fix predictable and insecure temporary file paths
**Vulnerability:** Installation scripts (`tools/os_installers/apt.sh`) downloaded files to predictable locations (`/tmp/yq`) or the current working directory, which risks symlink attacks and overwriting existing files, especially when running as `sudo`.
**Learning:** Using elevated privileges with predictable paths or working directories can lead to local privilege escalation.
**Prevention:** Always use securely generated random directories like `mktemp -d` to prevent local privilege escalation and symlink attacks.
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 linting errors to pass CI.

The static analysis flagged several issues:

  • Line 1: Should be a top-level heading (# instead of ##) per MD041
  • Line 1: Needs a blank line after the heading per MD022
  • Lines 2-4: Line length exceeds 80 characters per MD013
πŸ“ Proposed fix for markdown linting
-## 2024-05-24 - [CRITICAL] Fix predictable and insecure temporary file paths
-**Vulnerability:** Installation scripts (`tools/os_installers/apt.sh`) downloaded files to predictable locations (`/tmp/yq`) or the current working directory, which risks symlink attacks and overwriting existing files, especially when running as `sudo`.
-**Learning:** Using elevated privileges with predictable paths or working directories can lead to local privilege escalation.
-**Prevention:** Always use securely generated random directories like `mktemp -d` to prevent local privilege escalation and symlink attacks.
+# Sentinel Security Notes
+
+## 2024-05-24 - [CRITICAL] Fix predictable and insecure temporary file paths
+
+**Vulnerability:** Installation scripts (`tools/os_installers/apt.sh`)
+downloaded files to predictable locations (`/tmp/yq`) or the current working
+directory, which risks symlink attacks and overwriting existing files,
+especially when running as `sudo`.
+
+**Learning:** Using elevated privileges with predictable paths or working
+directories can lead to local privilege escalation.
+
+**Prevention:** Always use securely generated random directories like
+`mktemp -d` to prevent local privilege escalation and symlink attacks.
πŸ“ 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 - [CRITICAL] Fix predictable and insecure temporary file paths
**Vulnerability:** Installation scripts (`tools/os_installers/apt.sh`) downloaded files to predictable locations (`/tmp/yq`) or the current working directory, which risks symlink attacks and overwriting existing files, especially when running as `sudo`.
**Learning:** Using elevated privileges with predictable paths or working directories can lead to local privilege escalation.
**Prevention:** Always use securely generated random directories like `mktemp -d` to prevent local privilege escalation and symlink attacks.
# Sentinel Security Notes
## 2024-05-24 - [CRITICAL] Fix predictable and insecure temporary file paths
**Vulnerability:** Installation scripts (`tools/os_installers/apt.sh`)
downloaded files to predictable locations (`/tmp/yq`) or the current working
directory, which risks symlink attacks and overwriting existing files,
especially when running as `sudo`.
**Learning:** Using elevated privileges with predictable paths or working
directories can lead to local privilege escalation.
**Prevention:** Always use securely generated random directories like
`mktemp -d` to prevent local privilege escalation and symlink attacks.
🧰 Tools
πŸͺ› GitHub Check: Lint Documentation

[failure] 4-4: Line length
.jules/sentinel.md:4:81 MD013/line-length Line length [Expected: 80; Actual: 140] 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: 125] 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: 253] 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 - [CRITICAL] Fix..."] 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 - [CRITICAL] Fix predictable and insecure temporary file paths"] 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 top-level heading to a
single '#' in .jules/sentinel.md, add a blank line immediately after that
heading, and wrap/reflow the long lines in the body (the lines mentioning the
vulnerability, learning, and prevention) so no line exceeds 80 characters;
ensure the three sections ("Vulnerability:", "Learning:", "Prevention:") remain
intact and readable after rewrapping.

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