fix(browser): allow double dots in filenames, normalize path traversal by segments - #83
Open
Ibochkarev wants to merge 1 commit into
Open
fix(browser): allow double dots in filenames, normalize path traversal by segments#83Ibochkarev wants to merge 1 commit into
Ibochkarev wants to merge 1 commit into
Conversation
Stop stripping dots that are not followed by a word character in Browser::sanitize(). Names like somefile..txt stay intact; path traversal remains Flysystem's job.
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.
Что сделано
Останавливает
Browser::sanitize()от переписывания имён файлов, содержащих последовательные точки внутри одного сегмента пути (напримерsomefile..txt).Старый
preg_replace('/\.(?![\w\-\~\s])/u', '', …)трактовал эти точки как небезопасные и превращал имя вsomefile.txt, поэтому delete/rename/download промахивались мимо реального файла. Этот паттерн убран. Мягкая чистка (URL-decode, strip tags, коллапс//) остаётся. Path traversal по-прежнему обрабатывается FlysystemWhitespacePathNormalizer, когда media source читает или пишет.Зачем нужно
somefile..txt— валидное имя. Пользователи могли его загрузить, а File Browser не мог удалить или переименовать, потому что sanitize менял путь первым. См. modxcms#16663.Как проверить
somefile..txt.../-пути по-прежнему не могут выйти за корень media source (Flysystem отвергает traversal).Связанные
Refs modxcms#16663
Оригинал: modxcms#16838