Skip to content

harden cache backend unserialize, PubSubHubbub verify token and Lucene fileList() - #248

Open
falkenhawk wants to merge 1 commit into
masterfrom
harden-cache-unserialize
Open

falkenhawk wants to merge 1 commit into
masterfrom
harden-cache-unserialize

Conversation

@falkenhawk

Copy link
Copy Markdown
Member

1) Cache backends: no objects from their own stored arrays

Zend_Cache_Backend_File stores the metadata of each cache entry (expiry, tags, ...) as a serialized array in a file next to the data.
Zend_Cache_Backend_TwoLevels stores each entry as a serialized array (data, lifetime, priority) in both of its backends.
Both unserialized these without restrictions. Anyone who can write to the cache - e.g. a shared temp directory, the default cache_dir, or a shared memcache - could plant serialized objects there, and unserializing them runs code like __wakeup() and __destruct() of classes the app has loaded.

Both now unserialize with allowed_classes => false, and treat anything that is not an array as a cache miss. Before, that ended with a fatal error.
These arrays only ever hold strings and numbers, because the cached data is always a string: Zend_Cache_Core serializes everything else before it reaches a backend.
So nothing changes for normal use. The cached data itself is not affected, Zend_Cache_Core with automatic_serialization unserializes it as before.

zf1-future did the same for TwoLevels in Shardj/zf1-future#363, and also removes such broken entries from the backends.
Shardj/zf1-future#595 did it for the File backend, and also for other places that unserialize their own data (Static backend, Zend_Date, Zend_Locale_Data, OpenId file storages, Lucene).

2) PubSubHubbub: random verify token

Zend_Feed_Pubsubhubbub_Subscriber generated hub.verify_token with uniqid(rand(), true) . time(), which is based on the current time and a weak random number.
The hub sends the token back when it confirms a subscription, so it should not be guessable.
It is now bin2hex(random_bytes(16)). The token is only ever compared as a whole, so its format does not matter.

3) Lucene: listing a removed index directory

Zend_Search_Lucene_Storage_Directory_Filesystem::fileList() did not check whether opendir() succeeded, e.g. after the directory was removed.
readdir(false) then throws a TypeError on php 8. On php 7 it returns null, never false, so the loop never ended.
It now returns an empty list, after the warning of opendir().

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.

1 participant