Prevent object injection through unserialize #69
Merged
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.
If a user sets a cookie containing an object it might execute some code inside the object when unserializing the object through the
__wakeup
magic method.This pull request attempts to prevent this by setting and getting cookies through json encode/decode. We've also provided some fallback by checking if the cookie's string contains a serialized object. If it doesn't, we still unserialize the cookie and re-set it using
json_encode
. If the cookie does contain a serialized object an exception will be thrown.This security fix will break your website if objects are set in cookies.
If you are using this in Fork CMS you will probably need to update the class that extends SpoonCookie as well and change the encoding in the same way as it was done in this PR
See https://www.owasp.org/index.php/PHP_Object_Injection for example