From 9e3f965ecb20c59ea994073be5a25e6c9904e018 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 20 Jun 2026 07:25:14 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A1=EF=B8=8F=20Sentinel:=20[CRITICAL]?= =?UTF-8?q?=20Fix=20unsafe=20path=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed insecure path handling in `StatusSocket.swift` where POSIX file APIs (`open()`) were called with raw path variables, leading to unsafe filesystem representations. Replaced raw POSIX calls with safe C-string pointer wrappers (`URL(fileURLWithPath:).withUnsafeFileSystemRepresentation`) to securely bridge file paths. Co-authored-by: acebytes <2820910+acebytes@users.noreply.github.com> --- .jules/sentinel.md | 4 ++++ Sources/Cacheout/Headless/StatusSocket.swift | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.jules/sentinel.md b/.jules/sentinel.md index b0fa4d9..ea4bf5a 100644 --- a/.jules/sentinel.md +++ b/.jules/sentinel.md @@ -134,3 +134,7 @@ grep -nE "O_NOFOLLOW|O_CLOEXEC|fchmod|withUnsafeFileSystemRepresentation" Int32 in + guard let pathPtr = pathPtr else { return -1 } + return open(pathPtr, O_RDONLY | O_NOFOLLOW | O_DIRECTORY | O_CLOEXEC) + } guard dirFd >= 0 else { throw StatusSocketError.directoryHardeningFailed(errno) } @@ -497,7 +500,10 @@ public final class StatusSocket: @unchecked Sendable { // component is rejected up front and we hold a stable fd for the rest // of the checks — no path resolution happens between type/size check // and read, closing the lstat → open TOCTOU window. - let fileFd = open(expandedPath, O_RDONLY | O_NOFOLLOW | O_CLOEXEC) + let fileFd = URL(fileURLWithPath: expandedPath).withUnsafeFileSystemRepresentation { pathPtr -> Int32 in + guard let pathPtr = pathPtr else { return -1 } + return open(pathPtr, O_RDONLY | O_NOFOLLOW | O_CLOEXEC) + } guard fileFd >= 0 else { let err = errno let reason = err == ELOOP ? "Refusing to follow symlink: \(expandedPath)"