π‘οΈ Sentinel: [CRITICAL] Fix predictable temp file vulnerability in apt.sh#57
π‘οΈ Sentinel: [CRITICAL] Fix predictable temp file vulnerability in apt.sh#57
Conversation
Replaced hardcoded `/tmp/yq` with a securely generated temp directory (`mktemp -d`) when downloading and installing `yq` in `tools/os_installers/apt.sh`. This prevents local privilege escalation and symlink attacks. Co-authored-by: kidchenko <5432753+kidchenko@users.noreply.github.com>
|
π 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
π WalkthroughWalkthroughThe change refactors the yq binary installation process in the apt.sh installer script to use a temporary directory created via Changes
Estimated code review effortπ― 2 (Simple) | β±οΈ ~8 minutes Poem
π₯ Pre-merge checks | β 3β Passed checks (3 passed)
βοΈ Tip: You can configure your own custom pre-merge checks in the settings. β¨ Finishing Touches
π§ͺ Generate unit tests (beta)
π Coding Plan
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
π€ Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tools/os_installers/apt.sh`:
- Around line 234-238: The temporary dir YQ_TMPDIR created by mktemp can be
orphaned if wget or sudo mv fails due to set -e; add a trap immediately after
creating YQ_TMPDIR to run rm -rf "$YQ_TMPDIR" on EXIT (and optionally on
INT/TERM) so cleanup always runs, ensure mktemp success is checked before
setting the trap, and if you need to preserve the directory on success remove or
reset the trap after the mv/chmod steps; reference the YQ_TMPDIR variable and
the sequence around mktemp, wget, sudo mv, sudo chmod and rm -rf to locate where
to add the trap.
βΉοΈ Review info
βοΈ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 29e21bcf-92a5-4a04-bae2-1d17c8f4ba3d
π Files selected for processing (1)
tools/os_installers/apt.sh
| YQ_TMPDIR=$(mktemp -d) | ||
| wget "https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64" -O "$YQ_TMPDIR/yq" | ||
| sudo mv "$YQ_TMPDIR/yq" /usr/local/bin/yq | ||
| sudo chmod +x /usr/local/bin/yq | ||
| rm -rf "$YQ_TMPDIR" |
There was a problem hiding this comment.
π οΈ Refactor suggestion | π Major
π§© Analysis chain
π Script executed:
#!/bin/bash
# Verify whether yq temp-dir cleanup is protected by trap.
rg -n -C2 'YQ_TMPDIR|trap .*YQ_TMPDIR|wget .*yq_linux_amd64|sudo mv .*yq|rm -rf "\$YQ_TMPDIR"' tools/os_installers/apt.shRepository: kidchenko/dotfiles
Length of output: 406
π Script executed:
head -20 tools/os_installers/apt.shRepository: kidchenko/dotfiles
Length of output: 579
π Script executed:
grep -n "set -e\|set -o errexit" tools/os_installers/apt.shRepository: kidchenko/dotfiles
Length of output: 70
π Script executed:
sed -n '230,240p' tools/os_installers/apt.shRepository: kidchenko/dotfiles
Length of output: 407
Add trap to guarantee temp dir cleanup on failure.
With set -e active (line 7), if wget or sudo mv fails at lines 235β236, the script exits immediately and skips the cleanup at line 238, orphaning the temporary directory. Use a trap to ensure cleanup runs unconditionally:
Proposed fix
YQ_TMPDIR=$(mktemp -d)
+ trap 'rm -rf "$YQ_TMPDIR"' EXIT
wget "https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64" -O "$YQ_TMPDIR/yq"
sudo mv "$YQ_TMPDIR/yq" /usr/local/bin/yq
sudo chmod +x /usr/local/bin/yq
- rm -rf "$YQ_TMPDIR"π 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.
| YQ_TMPDIR=$(mktemp -d) | |
| wget "https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64" -O "$YQ_TMPDIR/yq" | |
| sudo mv "$YQ_TMPDIR/yq" /usr/local/bin/yq | |
| sudo chmod +x /usr/local/bin/yq | |
| rm -rf "$YQ_TMPDIR" | |
| YQ_TMPDIR=$(mktemp -d) | |
| trap 'rm -rf "$YQ_TMPDIR"' EXIT | |
| wget "https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64" -O "$YQ_TMPDIR/yq" | |
| sudo mv "$YQ_TMPDIR/yq" /usr/local/bin/yq | |
| sudo chmod +x /usr/local/bin/yq |
π€ 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 temporary dir
YQ_TMPDIR created by mktemp can be orphaned if wget or sudo mv fails due to set
-e; add a trap immediately after creating YQ_TMPDIR to run rm -rf "$YQ_TMPDIR"
on EXIT (and optionally on INT/TERM) so cleanup always runs, ensure mktemp
success is checked before setting the trap, and if you need to preserve the
directory on success remove or reset the trap after the mv/chmod steps;
reference the YQ_TMPDIR variable and the sequence around mktemp, wget, sudo mv,
sudo chmod and rm -rf to locate where to add the trap.
π¨ Severity: CRITICAL
π‘ Vulnerability: Predictable temporary file path (
/tmp/yq) used when downloadingyqand moving it to/usr/local/binusingsudo. This makes the script vulnerable to symlink attacks, potentially allowing a malicious local user to overwrite arbitrary files as root.π― Impact: Local Privilege Escalation / Arbitrary File Overwrite
π§ Fix: Switched to using a securely generated temporary directory via
mktemp -d, which creates a directory with strict permissions and random name, ensuring only the executing user can access it. Cleaned up the directory after use.β Verification: Ran
./build.shsyntax check and reviewed the diff to ensure thesudo mvcommand now operates on a securely generated path.PR created automatically by Jules for task 5349592463307284626 started by @kidchenko
Summary by CodeRabbit