Skip to content

Commit b931e08

Browse files
authored
Merge pull request #974 from svdv22/unserialize-user-input
Update advice for unserializing user input
2 parents bcbf43b + 3db7ff2 commit b931e08

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

_posts/10-04-01-Data-Filtering.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ libraries like [HTML Purifier][html-purifier] exist for this reason.
5252

5353
It is dangerous to `unserialize()` data from users or other untrusted sources. Doing so can allow malicious users to instantiate objects (with user-defined properties) whose destructors will be executed, **even if the objects themselves aren't used**. You should therefore avoid unserializing untrusted data.
5454

55-
If you absolutely must unserialize data from untrusted sources, use PHP 7's [`allowed_classes`][unserialize] option to restrict which object types are allowed to be unserialized.
55+
Use a safe, standard data interchange format such as JSON (via [`json_decode`][json_decode] and [`json_encode`][json_encode]) if you need to pass serialized data to the user.
5656

5757
### Validation
5858

@@ -69,4 +69,5 @@ phone number, or age when processing a registration submission.
6969
[5]: https://www.php.net/function.filter-input
7070
[6]: https://www.php.net/security.filesystem.nullbytes
7171
[html-purifier]: http://htmlpurifier.org/
72-
[unserialize]: https://www.php.net/manual/function.unserialize.php
72+
[json_decode]: https://www.php.net/manual/function.json-decode.php
73+
[json_encode]: https://www.php.net/manual/function.json-encode.php

0 commit comments

Comments
 (0)