Can a phplist developer please tell me why phplist doesnât use phpâs built-in error_log() function?
For example, phplistâs mysqli.inc file defines a custom logging function sqllog(). This sqllog() function takes a required argument of the log file path, which is hard-coded throughout the same mysqli.inc file to be some files in â/tmp/â
^ This is extremely concerning, since â/tmp/â is often setup as a 777 directory (read/write permissions granted to all users, groups, and other). Therefore, if an sql query included sensitive content (ie: passwords, user pii, etc), that query may be readable to all users and processes on the server.
Is there something Iâm missing as to why phplist intentionally avoids the error_log() function built-into php?
Hey @maltfield, thanks for the feedback.
I donât think using error_log with the default configuration would be the best option as it would spam the error log. Instead, I am thinking about creating a new temporary folder where the access is limited to phpList and log the logs there, and also a user can configure the log file path in their config file.
Would this work for you?
Iâm definitely not a php expert, but I strongly lean towards using built-in functionality rather than reinventing the wheel.
I donât think using error_log with the default configuration would be the best option as it would spam the error log.
But thatâs why php.ini allows the admin to configure what is written to the error logs. For example, you could have the sql stats be written as a E_STRICT using trigger_error():
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Error handling and logging ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
âŠ
; By default, PHP is set to take action on all errors, notices and warnings EXCEPT
; those related to E_NOTICE and E_STRICT, which together cover best practices and
; recommended coding standards in PHP. For performance reasons, this is the
; recommend error reporting setting. Your production server shouldnât be wasting
; resources complaining about best practices and coding standards. Thatâs what
; development servers and development settings are for.
âŠ
; Error Level Constants:
; E_ALL - All errors and warnings (includes E_STRICT as of PHP 5.4.0)
; E_ERROR - fatal run-time errors
; E_RECOVERABLE_ERROR - almost fatal run-time errors
; E_WARNING - run-time warnings (non-fatal errors)
; E_PARSE - compile-time parse errors
; E_NOTICE - run-time notices (these are warnings which often result
; from a bug in your code, but itâs possible that it was
; intentional (e.g., using an uninitialized variable and
; relying on the fact itâs automatically initialized to an
; empty string)
; E_STRICT - run-time notices, enable to have PHP suggest changes
; to your code which will ensure the best interoperability
; and forward compatibility of your code
; E_CORE_ERROR - fatal errors that occur during PHPâs initial startup
; E_CORE_WARNING - warnings (non-fatal errors) that occur during PHPâs
; initial startup
; E_COMPILE_ERROR - fatal compile-time errors
; E_COMPILE_WARNING - compile-time warnings (non-fatal errors)
; E_USER_ERROR - user-generated error message
; E_USER_WARNING - user-generated warning message
; E_USER_NOTICE - user-generated notice message
; E_DEPRECATED - warn about code that will not work in future versions
; of PHP
; E_USER_DEPRECATED - user-generated deprecation warnings
; Common Values:
; E_ALL (Show all errors, warnings and notices including coding standards.)
; E_ALL & ~E_NOTICE (Show all errors, except for notices)
; E_ALL & ~E_NOTICE & ~E_STRICT (Show all errors, except for notices and coding standards warnings.)
; E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR (Show only errors)
; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
; Development Value: E_ALL
; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT
; PHP: Runtime Configuration - Manual
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
And, in any case, you can overwrite what error types are actually logged at runtime with error_reporting(). This is something that phplist already does
But even then, the best you can do is make the dir/files in your new temp dir/log file 0600 (not sure if even thatâs achievable) and owned by the web server (so still accessible by other vhosts). But if you use trigger_error(), then theyâre passed to the web serverâs logs which can actually be setup so theyâre only readable by rootâŠ