fix(server): set sticky bit on socket files (#2141)

This commit is contained in:
Thomas Linford 2023-04-05 17:36:47 +02:00 committed by GitHub
parent 3973873252
commit 778d57c3c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -278,7 +278,10 @@ pub fn start_server(mut os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
move || { move || {
drop(std::fs::remove_file(&socket_path)); drop(std::fs::remove_file(&socket_path));
let listener = LocalSocketListener::bind(&*socket_path).unwrap(); let listener = LocalSocketListener::bind(&*socket_path).unwrap();
set_permissions(&socket_path, 0o700).unwrap(); // set the sticky bit to avoid the socket file being potentially cleaned up
// https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html states that for XDG_RUNTIME_DIR:
// "To ensure that your files are not removed, they should have their access time timestamp modified at least once every 6 hours of monotonic time or the 'sticky' bit should be set on the file. "
set_permissions(&socket_path, 0o1700).unwrap();
for stream in listener.incoming() { for stream in listener.incoming() {
match stream { match stream {
Ok(stream) => { Ok(stream) => {