Repository navigation
Conversation
…leHandler::validateKey()
The file handler concatenates the cache key with the cache store path, so a
key that contains a directory separator or a traversal sequence can address
files outside the cache directory. BaseHandler::validateKey() only rejects
such characters when Config\Cache::$reservedCharacters happens to contain
them, and that setting is commonly emptied when several handlers share the
same keys (for example file storage next to Redis).
FileHandler::validateKey() now always rejects "/", "\", a null byte, and
traversal sequences ("..") in both the key and the prefix, independently of
the configured reservedCharacters, throwing
CodeIgniter\Exceptions\InvalidArgumentException. Valid keys keep the
existing PSR-6 validation and hashing behaviour.
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.
Description
FileHandlerbuilds the path of a cache item by appending the validated key to the cache store path:BaseHandler::validateKey()rejects/,\and..only indirectly, throughConfig\Cache::$reservedCharacters. That setting is often emptied when a single key namespace is shared by several handlers (for example file storage alongside Redis/Memcached), and in that case a key such as../fooorsub/keyreaches the file system unchanged, allowing a write/read/unlink outside the cache directory (path traversal).This PR makes the file handler's own validation authoritative, independently of
$reservedCharacters:FileHandler::validateKey()now rejects/,\, the null byte, and traversal sequences (..) in both the key and the prefix, and throwsCodeIgniter\Exceptions\InvalidArgumentException.BaseHandler::validateKey()(string type, non-empty, configured reserved characters) and MD5 hashing when the prefixed key exceedsMAX_KEY_LENGTH.reservedCharactersso it does not leak state into other tests.Fixes the traversal vector without requiring applications to configure
reservedCharacters.Checklist: