Plugin hard-codes mpdf tempdir to potenitally non-writeable location
-
There’s a minor problem with this plugin whereby it hard-codes the location of the mpdf tmp dir as a sub-dir of the plugin install dir and proceeds to use it without checking it exists.
In a locked-down WordPress install, the plugin dirs are not writable.
The mpdf manual recommends using a non-default tmp dir location:
https://mpdf.github.io/installation-setup/folders-for-temporary-files.html
It’s possible using the “cmplz_mpdf_args” filter to specify the location of the mpdf temp dir rather than using the default “complianz-gdpr/assets/vendor/mpdf/mpdf/tmp” location using something like this:
function ainet_cmplz_mpdf_args( $args ) {
// Set the tempdir location as by default it uses the vendor dir.
$args[ 'tempDir' ] = get_temp_dir();
return $args;
}
add_filter( 'cmplz_mpdf_args', 'ainet_cmplz_mpdf_args', 10, 1 );There is however a cmplz tmp dir cleanup job that calls recursively_clear_directory($dir) with $dir = cmplz_path . ‘/assets/vendor/mpdf/mpdf/tmp’.
When the plugin dirs are not writeable, the temp dir does not exist and this gets logged (filesystem location sanitised):
PHP Warning: scandir(/xxxxx/wp-content/plugins/complianz-gdpr//assets/vendor/mpdf/mpdf/tmp): Failed to open directory: No such file or directory in /xxxxx/wp-content/plugins/complianz-gdpr/documents/class-document.php on line 2040
Warning: scandir(/xxxxx/wp-content/plugins/complianz-gdpr//assets/vendor/mpdf/mpdf/tmp): Failed to open directory: No such file or directory in /xxxxx/wp-content/plugins/complianz-gdpr/documents/class-document.php on line 2040
PHP Warning: scandir(): (errno 2): No such file or directory in /xxxxx/wp-content/plugins/complianz-gdpr/documents/class-document.php on line 2040
Warning: scandir(): (errno 2): No such file or directory in /xxxxx/wp-content/plugins/complianz-gdpr/documents/class-document.php on line 2040
PHP Fatal error: Uncaught TypeError: array_diff(): Argument #1 ($array) must be of type array, bool given in /xxxxx/wp-content/plugins/complianz-gdpr/documents/class-document.php:2040
Stack trace:
#0 /xxxxx/wp-content/plugins/complianz-gdpr/documents/class-document.php(2040): array_diff()
#1 /xxxxx/wp-content/plugins/complianz-gdpr/documents/class-document.php(2021): cmplz_document->recursively_clear_directory()
#2 /xxxxx/wp-content/plugins/complianz-gdpr/proof-of-consent/class-proof-of-consent.php(293): cmplz_document->generate_pdf()
#3 /xxxxx/wp-includes/class-wp-hook.php(324): cmplz_proof_of_consent->generate_cookie_policy_snapshot()
#4 /xxxxx/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
#5 /xxxxx/wp-includes/plugin.php(565): WP_Hook->do_action()
#6 phar:///usr/local/bin/wp/vendor/wp-cli/cron-command/src/Cron_Event_Command.php(361): do_action_ref_array()
#7 phar:///usr/local/bin/wp/vendor/wp-cli/cron-command/src/Cron_Event_Command.php(284): Cron_Event_Command::run_event()
#8 [internal function]: Cron_Event_Command->run()
#9 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php(100): call_user_func()
#10 [internal function]: WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}()
#11 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/Subcommand.php(497): call_user_func()
#12 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(441): WP_CLI\Dispatcher\Subcommand->invoke()
#13 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(464): WP_CLI\Runner->run_command()
#14 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1295): WP_CLI\Runner->run_command_and_exit()
#15 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(28): WP_CLI\Runner->start()
#16 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/bootstrap.php(83): WP_CLI\Bootstrap\LaunchRunner->process()
#17 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php(32): WP_CLI\bootstrap()
#18 phar:///usr/local/bin/wp/php/boot-phar.php(20): include('...')
#19 /usr/local/bin/wp(4): include('...')
#20 {main}
thrown in /xxxxx/wp-content/plugins/complianz-gdpr/documents/class-document.php on line 2040
Fatal error: Uncaught TypeError: array_diff(): Argument #1 ($array) must be of type array, bool given in /xxxxx/wp-content/plugins/complianz-gdpr/documents/class-document.php:2040Would it be possible to either have a hook to set the temp dir location or have recursively_clear_directory() use the mpdf-configured temp dir location?
Thanks.
Ronny
- You must be logged in to reply to this topic.