-
Notifications
You must be signed in to change notification settings - Fork 0
π‘οΈ Sentinel: [CRITICAL] Fix TOCTOU vulnerability in config permissions enforcement #278
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,14 @@ public actor DaemonMode: StatusSocket.DataSource { | |
| return | ||
| } | ||
|
|
||
| // Enforce 0600 permissions | ||
| chmod(path, 0o600) | ||
| // Enforce 0600 permissions safely to avoid TOCTOU symlink attacks | ||
| let fd = open(path, O_RDONLY | O_NOFOLLOW) | ||
| if fd >= 0 { | ||
| fchmod(fd, 0o600) | ||
|
Comment on lines
+970
to
+972
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.
Opening the config with Useful? React with πΒ / π. |
||
| close(fd) | ||
| } else { | ||
| logger.error("Failed to safely open config for permissions check at \(path, privacy: .public)") | ||
| } | ||
|
|
||
| // Read file | ||
|
Comment on lines
+974
to
978
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.
If Useful? React with πΒ / π. |
||
| 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.
Using
open(path, O_RDONLY | O_NOFOLLOW)can block indefinitely when the path is a FIFO with no writer, because read-onlyopen()on FIFOs blocks unlessO_NONBLOCKis set. SincefileExists(atPath:)is true for FIFOs, a malicious or accidental replacement of the config path with a named pipe can stall this reload path and prevent config processing.Useful? React with πΒ / π.