From 301a8f121800c5e3404191126912719b8e8e3d8b Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 5 Apr 2026 06:12:29 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A1=EF=B8=8F=20Sentinel:=20Fix=20comma?= =?UTF-8?q?nd=20injection=20in=20toolExists?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaced `bash -c` shell interpolation with direct `Process` execution. Co-authored-by: acebytes <2820910+acebytes@users.noreply.github.com> --- .jules/sentinel.md | 4 ++++ Sources/Cacheout/Models/CacheCategory.swift | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 .jules/sentinel.md diff --git a/.jules/sentinel.md b/.jules/sentinel.md new file mode 100644 index 0000000..572ba5f --- /dev/null +++ b/.jules/sentinel.md @@ -0,0 +1,4 @@ +## 2024-11-20 - Command Injection in Tool Validation +**Vulnerability:** Found a command injection vulnerability in `toolExists` within `Sources/Cacheout/Models/CacheCategory.swift` where user-controlled input (`tool`) was interpolated into a shell wrapper: `shell("/usr/bin/which \(tool)")`. +**Learning:** String interpolation in shell commands (`bash -c`) evaluates variables dynamically in the shell, opening severe command injection vectors if the input contains spaces, pipelines, or glob characters. +**Prevention:** Always avoid shell wrappers (`bash -c`) when possible. Use direct `Process` execution (e.g., `/usr/bin/env` with `arguments = ["which", tool]`) where dynamic arguments are passed safely as an array, entirely bypassing the shell's evaluation step. diff --git a/Sources/Cacheout/Models/CacheCategory.swift b/Sources/Cacheout/Models/CacheCategory.swift index 7b3d942..ba20985 100644 --- a/Sources/Cacheout/Models/CacheCategory.swift +++ b/Sources/Cacheout/Models/CacheCategory.swift @@ -186,8 +186,23 @@ struct CacheCategory: Identifiable, Hashable { } private func toolExists(_ tool: String) -> Bool { - let result = shell("/usr/bin/which \(tool)") - return result != nil && !result!.isEmpty + let process = Process() + process.executableURL = URL(fileURLWithPath: "/usr/bin/env") + process.arguments = ["which", tool] + process.standardOutput = FileHandle.nullDevice + process.standardError = FileHandle.nullDevice + process.environment = [ + "PATH": "/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin", + "HOME": FileManager.default.homeDirectoryForCurrentUser.path + ] + + do { + try process.run() + process.waitUntilExit() + return process.terminationStatus == 0 + } catch { + return false + } } private func runProbe(_ command: String) -> String? {