-
Notifications
You must be signed in to change notification settings - Fork 0
π‘οΈ Sentinel: [HIGH] Fix TOCTOU vulnerability in file permissions #290
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,16 @@ public actor DaemonMode: StatusSocket.DataSource { | |
| return | ||
| } | ||
|
|
||
| // Enforce 0600 permissions | ||
| chmod(path, 0o600) | ||
| // Enforce 0600 permissions using O_NOFOLLOW to prevent TOCTOU symlink attacks | ||
| let url = URL(fileURLWithPath: path) | ||
| url.withUnsafeFileSystemRepresentation { cPath in | ||
| guard let cPath = cPath else { return } | ||
| let fd = open(cPath, O_RDONLY | O_NOFOLLOW) | ||
| if fd >= 0 { | ||
|
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.
The new secure-open block silently ignores Useful? React with πΒ / π. |
||
| fchmod(fd, 0o600) | ||
| close(fd) | ||
| } | ||
| } | ||
|
|
||
| // 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.
O_RDONLYwhen opening file forfchmodOpening the config file with
O_RDONLY | O_NOFOLLOWcan fail withEACCESwhen the file is owner-owned but currently not readable (for example mode0000/0200), so the permission fix is skipped and the subsequentcontents(atPath:)read fails. This is a regression from the previouschmod(path, 0o600)behavior, which could recover such files by tightening permissions first, and it can break startup/reload for mis-permissioned autopilot configs.Useful? React with πΒ / π.