-
-
Notifications
You must be signed in to change notification settings - Fork 786
Add realpath error handling, temp cleanup on fatal errors, credentials sanitization #1922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add realpath error handling, temp cleanup on fatal errors, credentials sanitization #1922
Conversation
imhayatunnabi
commented
Oct 15, 2025
- Missing Error Handling for realpath() Failures
- Temporary Directory Not Cleaned Up on Certain Failures
- Database Connection Error Messages Expose Credentials
- Port Validation Accepts Invalid Ports
|
could you rebase this with |
a0c1462 to
5e29175
Compare
|
Is this ok now ? @freekmurze |
890a51d to
d262b49
Compare
…ntial sanitization, and robust port validation
d262b49 to
c8e2cf4
Compare
|
rebase is done. was facing issue with my upstream. now resolved. rebased and updated in the latest commit. @freekmurze |
freekmurze
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this. I think the changes are probably a bit too strict (and the code is a bit too complicated to my eyes).
There is one new exception that you introduced that we could keep, but could you refactor it so it follows the patterns of the other exceptions?
src/Helpers/CredentialSanitizer.php
Outdated
| @@ -0,0 +1,47 @@ | |||
| <?php | |||
|
|
|||
| namespace Spatie\Backup\Helpers; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this class
| ->force() | ||
| ->create() | ||
| ->empty(); | ||
| $cleanupRegistered = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the added lines
src/Tasks/Backup/BackupJob.php
Outdated
| $this->copyToBackupDestinations($zipFile); | ||
| } catch (Exception $exception) { | ||
| consoleOutput()->error("Backup failed because: {$exception->getMessage()}.".PHP_EOL.$exception->getTraceAsString()); | ||
| $sanitizedError = CredentialSanitizer::sanitizeException($exception); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this, it think just throwing the exception is fine.
src/Tasks/Backup/BackupJob.php
Outdated
| try { | ||
| if (! $backupDestination->isReachable()) { | ||
| throw new Exception("Could not connect to disk {$backupDestination->diskName()} because: {$backupDestination->connectionError()}"); | ||
| $sanitizedError = CredentialSanitizer::sanitizeMessage($backupDestination->connectionError()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with throwing an exception here. You don't need to sanitize the message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do refactor the exception to how it's done for the other exceptions. See BackupFailed
src/Tasks/Backup/BackupJob.php
Outdated
| $this->sendNotification(new BackupWasSuccessful($backupDestination)); | ||
| } catch (Exception $exception) { | ||
| consoleOutput()->error("Copying zip failed because: {$exception->getMessage()}."); | ||
| $sanitizedError = CredentialSanitizer::sanitizeMessage($exception->getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this, I think the current exception is good enough
|
|
||
| if (isset($dbConfig['port'])) { | ||
| if (filter_var($dbConfig['port'], FILTER_VALIDATE_INT, [ | ||
| $port = $dbConfig['port']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this. It'll fail elsewhere if the port is not correct.
| $path .= DIRECTORY_SEPARATOR; | ||
| $realPath = realpath($path); | ||
|
|
||
| if ($realPath === false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with excluded paths being non-existent. Remove all changes to this function.
|
@freekmurze any review or update ? |
|
@freekmurze about that .?? |