Repository navigation
security: bind media paths and validate upload codes - #676
Open
obaidur-dev wants to merge 1 commit into
Open
obaidur-dev wants to merge 1 commit into
obaidur-dev wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Two related defects share one input.
UploadController::saveMedia()builds the storage path from the client-suppliedcodeand file extension without validating either:codecontaining..segments is normalized by Flysystem into a write inside another user's directory or at the storage root.codeor extension containing a double quote reaches theIN ("...")list inMediaRepository::runWithFileSort()when a gallery is sorted by size. It injects aUNIONrow and leaks arbitrary database values into the page.This change:
codeto^[A-Za-z0-9_-]{1,64}$and the extension to^[A-Za-z0-9]{0,32}$, returning400for anything else,IN (...)lists inMediaRepository, including the tag query at line 350, with bound placeholders through a smallbuildPlaceholders()helper,IN ()syntax error.Affected release: 3.8.2. Files:
app/Controllers/UploadController.phplines 190 to 201 andapp/Database/Repositories/MediaRepository.phplines 234, 245 and 350.Tests
tests/Feature/Media/StoragePathSqlInjectionTest.phpuploads a file whose code carries theUNIONpayload and checks that the gallery no longer returns the injected row. Before the fix 3 of its 4 tests fail; after the fix all 4 pass.tests/Feature/Upload/PathTraversalTest.phpuploads with../pubusrAA/...and checks that the request is rejected and nothing is written outside the uploader's directory. Before the fix 1 test fails (201 instead of 400); after the fix both pass.