diff --git a/web/pgadmin/utils/enhanced_log_rotation.py b/web/pgadmin/utils/enhanced_log_rotation.py index ae45978b4..33897b3c3 100644 --- a/web/pgadmin/utils/enhanced_log_rotation.py +++ b/web/pgadmin/utils/enhanced_log_rotation.py @@ -7,6 +7,7 @@ # ########################################################################## +import os import re from logging import handlers @@ -46,6 +47,20 @@ class EnhancedRotatingFileHandler(handlers.TimedRotatingFileHandler, backupCount=backup_count, encoding=encoding) + # Create new log files with mode 0o600 so they are not world/group + # readable. Pre-existing files keep their permissions; the parent + # DATA_DIR is already 0o700 on POSIX, so this is defense-in-depth. + # On Windows the mode arg to os.open is ignored — fall back to the + # default behavior there. + def _open(self): + if os.name == 'nt': + return super()._open() + flags = os.O_WRONLY | os.O_CREAT | ( + os.O_APPEND if self.mode == 'a' else os.O_TRUNC) + fd = os.open(self.baseFilename, flags, 0o600) + return os.fdopen(fd, self.mode, encoding=self.encoding, + errors=getattr(self, 'errors', None)) + # Time & Size combined rollover def shouldRollover(self, record): return handlers.TimedRotatingFileHandler.shouldRollover(self, record) \