From 12a8c54331a85949fc2ae963d18f835e21837739 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Tue, 8 Apr 2025 16:43:36 -0500 Subject: [PATCH 1/2] Handle and log skipped unsafe files during restore Introduced a mechanism to track and log potentially unsafe files skipped during the restore process. These files are collected in an array and displayed as warnings before exiting, improving transparency and debugging capability. --- app/Console/Commands/RestoreFromBackup.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/RestoreFromBackup.php b/app/Console/Commands/RestoreFromBackup.php index 0478bcd929..b667ea9dec 100644 --- a/app/Console/Commands/RestoreFromBackup.php +++ b/app/Console/Commands/RestoreFromBackup.php @@ -200,6 +200,7 @@ class RestoreFromBackup extends Command */ public function handle() { + $unsafe_files = []; $dir = getcwd(); if( $dir != base_path() ) { // usually only the case when running via webserver, not via command-line Log::debug("Current working directory is: $dir, changing directory to: ".base_path()); @@ -338,7 +339,9 @@ class RestoreFromBackup extends Command if ($last_pos !== false) { $extension = strtolower(pathinfo($raw_path, PATHINFO_EXTENSION)); if (!in_array($extension, $good_extensions)) { - $this->warn('Potentially unsafe file ' . $raw_path . ' is being skipped'); + // gathering potentially unsafe files here to return at exit + $unsafe_files[] = $raw_path; + Log::debug('Potentially unsafe file '.$raw_path.' is being skipped'); $boring_files[] = $raw_path; continue 2; } @@ -372,6 +375,11 @@ class RestoreFromBackup extends Command if ($this->option('sanitize-guess-prefix')) { $prefix = SQLStreamer::guess_prefix($sql_contents); $this->line($prefix); + if (count($unsafe_files) > 0) { + foreach ($unsafe_files as $unsafe_file) { + $this->warn('Potentially unsafe file '.$unsafe_file.' is being skipped'); + } + } return $this->info("Re-run this command with '--sanitize-with-prefix=".$prefix."' to see an attempt to sanitize your SQL."); } From dd078785acc3b884531f4acf4529997a4c398046 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Tue, 8 Apr 2025 18:06:18 -0500 Subject: [PATCH 2/2] always show unsafe files --- app/Console/Commands/RestoreFromBackup.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/Console/Commands/RestoreFromBackup.php b/app/Console/Commands/RestoreFromBackup.php index b667ea9dec..d5a6847ec8 100644 --- a/app/Console/Commands/RestoreFromBackup.php +++ b/app/Console/Commands/RestoreFromBackup.php @@ -200,7 +200,6 @@ class RestoreFromBackup extends Command */ public function handle() { - $unsafe_files = []; $dir = getcwd(); if( $dir != base_path() ) { // usually only the case when running via webserver, not via command-line Log::debug("Current working directory is: $dir, changing directory to: ".base_path()); @@ -290,6 +289,7 @@ class RestoreFromBackup extends Command $interesting_files = []; $boring_files = []; + $unsafe_files = []; for ($i = 0; $i < $za->numFiles; $i++) { $stat_results = $za->statIndex($i); @@ -375,11 +375,7 @@ class RestoreFromBackup extends Command if ($this->option('sanitize-guess-prefix')) { $prefix = SQLStreamer::guess_prefix($sql_contents); $this->line($prefix); - if (count($unsafe_files) > 0) { - foreach ($unsafe_files as $unsafe_file) { - $this->warn('Potentially unsafe file '.$unsafe_file.' is being skipped'); - } - } + return $this->info("Re-run this command with '--sanitize-with-prefix=".$prefix."' to see an attempt to sanitize your SQL."); } @@ -513,6 +509,11 @@ class RestoreFromBackup extends Command } else { $this->info(count($interesting_files).' files were succesfully transferred'); } + if (count($unsafe_files) > 0) { + foreach ($unsafe_files as $unsafe_file) { + $this->warn('Potentially unsafe file '.$unsafe_file.' was skipped'); + } + } foreach ($boring_files as $boring_file) { $this->warn($boring_file.' was skipped.'); }