From 4b1b80bc8a7a92ccda3e363980f4398e6cedaa4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hanno=20B=C3=B6ck?= Date: Mon, 24 Apr 2023 16:03:28 +0200 Subject: [PATCH] dispatch-conf: Avoid race when accessing log file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit First creating the file and then running chmod creates a security risk where a user could access the file. Avoid this by enforcing the file permissions via umask. Signed-off-by: Hanno Böck --- bin/dispatch-conf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/dispatch-conf b/bin/dispatch-conf index 3dbfb0ed69..154b26ff56 100755 --- a/bin/dispatch-conf +++ b/bin/dispatch-conf @@ -119,8 +119,9 @@ class dispatch: if os.path.isfile(self.options["log-file"]) or not os.path.exists( self.options["log-file"] ): + old_umask = os.umask(0o077) open(self.options["log-file"], "w").close() # Truncate it - os.chmod(self.options["log-file"], 0o600) + os.umask(old_umask) pager = self.options.get("pager") if pager is None or not cmd_var_is_valid(pager):