Skip to content

Conversation

@imhayatunnabi
Copy link
Contributor

  • 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

@freekmurze
Copy link
Member

could you rebase this with main?

@imhayatunnabi imhayatunnabi force-pushed the fix/teamp-cleanup-credential-sanitisation branch 2 times, most recently from a0c1462 to 5e29175 Compare October 15, 2025 12:41
@imhayatunnabi
Copy link
Contributor Author

Is this ok now ? @freekmurze

@imhayatunnabi imhayatunnabi force-pushed the fix/teamp-cleanup-credential-sanitisation branch from 890a51d to d262b49 Compare October 15, 2025 14:50
…ntial sanitization, and

  robust port validation
@imhayatunnabi imhayatunnabi force-pushed the fix/teamp-cleanup-credential-sanitisation branch from d262b49 to c8e2cf4 Compare October 15, 2025 14:56
@imhayatunnabi
Copy link
Contributor Author

rebase is done. was facing issue with my upstream. now resolved. rebased and updated in the latest commit. @freekmurze

Copy link
Member

@freekmurze freekmurze left a 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?

@@ -0,0 +1,47 @@
<?php

namespace Spatie\Backup\Helpers;
Copy link
Member

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the added lines

$this->copyToBackupDestinations($zipFile);
} catch (Exception $exception) {
consoleOutput()->error("Backup failed because: {$exception->getMessage()}.".PHP_EOL.$exception->getTraceAsString());
$sanitizedError = CredentialSanitizer::sanitizeException($exception);
Copy link
Member

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.

try {
if (! $backupDestination->isReachable()) {
throw new Exception("Could not connect to disk {$backupDestination->diskName()} because: {$backupDestination->connectionError()}");
$sanitizedError = CredentialSanitizer::sanitizeMessage($backupDestination->connectionError());
Copy link
Member

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.

Copy link
Member

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

$this->sendNotification(new BackupWasSuccessful($backupDestination));
} catch (Exception $exception) {
consoleOutput()->error("Copying zip failed because: {$exception->getMessage()}.");
$sanitizedError = CredentialSanitizer::sanitizeMessage($exception->getMessage());
Copy link
Member

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'];
Copy link
Member

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) {
Copy link
Member

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.

@imhayatunnabi
Copy link
Contributor Author

@freekmurze any review or update ?

@imhayatunnabi
Copy link
Contributor Author

@freekmurze about that .??

@imhayatunnabi imhayatunnabi changed the title fix: add realpath error handling, temp cleanup on fatal errors, credentials sanitisation Add realpath error handling, temp cleanup on fatal errors, credentials sanitization Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants