From f49c9d7cd1d33586fbd106057a894b3effc04331 Mon Sep 17 00:00:00 2001 From: Andrew Price Date: Sat, 31 Aug 2024 18:35:15 +0100 Subject: [PATCH 1/2] unix: Don't create world-writable files when safe save is enabled When the "filesystem/on_save/safe_save_on_backup_then_rename" option is enabled files are created with 0666 permissions (-rw-rw-rw-) which is too loose. Use 0644 (-rw-r--r--) instead which is how the files would normally be created with the setting disabled and the system umask taken into account. --- drivers/unix/file_access_unix.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/unix/file_access_unix.cpp b/drivers/unix/file_access_unix.cpp index 32f2d7dd79..5c6c04e0be 100644 --- a/drivers/unix/file_access_unix.cpp +++ b/drivers/unix/file_access_unix.cpp @@ -97,7 +97,7 @@ Error FileAccessUnix::open_internal(const String &p_path, int p_mode_flags) { last_error = ERR_FILE_CANT_OPEN; return last_error; } - fchmod(fd, 0666); + fchmod(fd, 0644); path = String::utf8(cs.ptr()); f = fdopen(fd, mode_string); From 64077ff3de40d12eec83501cb06280a0e02027fc Mon Sep 17 00:00:00 2001 From: Andrew Price Date: Fri, 6 Sep 2024 19:32:35 +0100 Subject: [PATCH 2/2] unix: Limit named pipe permissions to the current user Named pipes created using the "pipe://" file access scheme should not be world-writable or readable. Limit their access to the current user by creating them with 0600 permissions instead of 0666. --- drivers/unix/file_access_unix_pipe.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/unix/file_access_unix_pipe.cpp b/drivers/unix/file_access_unix_pipe.cpp index 34758e8c7d..bdf02f5379 100644 --- a/drivers/unix/file_access_unix_pipe.cpp +++ b/drivers/unix/file_access_unix_pipe.cpp @@ -65,7 +65,7 @@ Error FileAccessUnixPipe::open_internal(const String &p_path, int p_mode_flags) struct stat st = {}; int err = stat(path.utf8().get_data(), &st); if (err) { - if (mkfifo(path.utf8().get_data(), 0666) != 0) { + if (mkfifo(path.utf8().get_data(), 0600) != 0) { last_error = ERR_FILE_CANT_OPEN; return last_error; }