-
Notifications
You must be signed in to change notification settings - Fork 0
π‘οΈ Sentinel: [HIGH] Fix TOCTOU vulnerability in config permissions #292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -966,8 +966,15 @@ public actor DaemonMode: StatusSocket.DataSource { | |
| return | ||
| } | ||
|
|
||
| // Enforce 0600 permissions | ||
| chmod(path, 0o600) | ||
| // Enforce 0600 permissions safely to prevent TOCTOU vulnerabilities | ||
| URL(fileURLWithPath: path).withUnsafeFileSystemRepresentation { pathPtr in | ||
| guard let ptr = pathPtr else { return } | ||
| let fd = open(ptr, O_RDONLY | O_NOFOLLOW | O_CLOEXEC) | ||
| if fd >= 0 { | ||
| fchmod(fd, 0o600) | ||
| close(fd) | ||
| } | ||
|
Comment on lines
+973
to
+976
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with πΒ / π. |
||
| } | ||
|
|
||
| // Read file | ||
| guard let data = FileManager.default.contents(atPath: path) else { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opening the file with
O_RDONLYmakes the permission-fix path fail for owner-unreadable configs (for example mode0200or0000):openreturnsEACCES,fchmodnever runs, and reload later errors on read. Before this commit,chmod(path, 0o600)could still repair those modes first, so this is a functional regression in self-healing permission enforcement. Consider using an access mode that can obtain an fd forfchmodwithout requiring immediate read permission (or retrying with a write-capable open).Useful? React with πΒ / π.