Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent object injection through unserialize #69

Merged
merged 3 commits into from
May 20, 2019

Conversation

StijnVrolijk
Copy link

@StijnVrolijk StijnVrolijk commented May 8, 2019

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

spoon/cookie/cookie.php Outdated Show resolved Hide resolved
If it's the case we still want to save it and send it back
If it does we don't want to throw an exception but just return the null
value
@carakas carakas merged commit 9a97858 into 2-3-8-base May 20, 2019
@carakas carakas deleted the fix-cookie-security-issue branch May 20, 2019 13:55
This pull request was closed.
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.

3 participants