Repository navigation
Fix 404 for backup files in subdirs - #140
Open
mariovillani wants to merge 1 commit into
Open
mariovillani wants to merge 1 commit into
mariovillani wants to merge 1 commit into
Conversation
|
BOOM! Your first PR with us, thank you so much! Someone will take a look at it shortly.
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WHY
BEFORE - What was wrong? What was happening before this PR?
Previously, downloading or deleting backups would fail and return a 404 error if the backup disk was configured to store backups in subdirectories (e.g., daily/backup.zip or app-name/2023-01-01.zip). This was happening because the isValidBackupFileName() security method was overly strict. It used basename($fileName) to ensure the path didn't contain any directory components, meaning it only accepted plain zip filenames that lived at the absolute root of the backup directory.
AFTER - What is happening after this PR?
Backups nested within subdirectories can now be successfully downloaded and deleted from the Backpack admin interface. The strict anti-path traversal check has been refactored to allow valid subdirectory structures while keeping the application fully protected against actual path traversal attacks.
HOW
How did you achieve that, in technical terms?
I removed the $fileName !== basename($fileName) check in isValidBackupFileName(), which was the restriction stripping out valid subdirectories. To safely replace this and maintain strong protection against Directory Traversal attacks, I introduced explicit string checks that reject malicious path patterns. The validation now ensures the file name ends with .zip AND explicitly blocks paths that:
Is it a breaking change or non-breaking change?
Non-breaking change.
How can we test the before & after?