Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 2024-05-24 - String Interpolation in Shell Commands
**Vulnerability:** Command injection vulnerability identified in `toolExists` within `CacheCategory.swift`, which utilized a shell wrapper (`/bin/bash -c`) with string interpolation to pass dynamic arguments: `shell("/usr/bin/which \(tool)")`.
**Learning:** String interpolation combined with shell wrappers allows arbitrary command injection if the interpolated variable contains shell metacharacters. Even inside `toolExists`, where `requiresTool` inputs seemed controlled internally, the code pattern itself was inherently unsafe.
**Prevention:** Avoid using shell wrappers (`/bin/bash -c`) and string interpolation for executing dynamic commands. Always use direct execution of the binary using `Process` with arguments safely separated into the `process.arguments` array.
16 changes: 14 additions & 2 deletions Sources/Cacheout/Models/CacheCategory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,20 @@ 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/which")
process.arguments = [tool]
process.standardOutput = FileHandle.nullDevice
process.standardError = FileHandle.nullDevice

do {
try process.run()
process.waitUntilExit()
return process.terminationStatus == 0
} catch {
return false
}
}

private func runProbe(_ command: String) -> String? {
Expand Down