Req #69908 [Asn->Sus]: Accept array for htmlspecialchars/htmlentities

From: Date: Tue, 27 Oct 2020 10:35:00 +0000
Subject: Req #69908 [Asn->Sus]: Accept array for htmlspecialchars/htmlentities
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-229937@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69908&edit=1 ID: 69908 Updated by: cmb@php.net Reported by: yohgaki@php.net Summary: Accept array for htmlspecialchars/htmlentities -Status: Assigned +Status: Suspended Type: Feature/Change Request Package: Strings related PHP Version: Irrelevant Assigned To: yohgaki Block user comment: N Private report: N New Comment: This feature request is obviously controversial, and as such needs to be discussed on the internals mailing list[1]. If you're still interested in having this, please forward your request to the list. For the time being, I'm suspending this ticket. [1] <https://www.php.net/mailing-lists.php#internals> Previous Comments: ------------------------------------------------------------------------ [2015-06-25 01:26:04] yohgaki@php.net @bishop It will make situation better, but not enough. I'm looking for optimization on IoT devices that took more than 10 sec to generate log report page by PHP. More than half of time is took by htmlspecialchars() and do the best htmlspecialchars() can do. ------------------------------------------------------------------------ [2015-06-24 13:58:45] bishop@php.net > Accept array and escape all elements when array is passed to them Why not just: array_map('htmlspecialchars', array ('&', '>', 'foo')); ------------------------------------------------------------------------ [2015-06-24 02:27:29] yohgaki@php.net @ircmaxwell I can understand your argument very well. Output security depends on "output context". This change is intended to escape relatively large number of variable at once. For example, HTML tables that have a lot of variables. The objective is not for improving security, but performance. We should balance security and performance/usability. Since I'm going to add array parameter support for conversion functions, we need to consider consistency also. I'll create RFC for this. ------------------------------------------------------------------------ [2015-06-23 15:27:59] ircmaxell@php.net I think this is the exact wrong way to solve the problem. Very rarely do you want to actually just do a "blind escape" of a bunch of variables. Instead, you need to know the context they will be used in. By accepting strings only, these security sensitive functions encourage you to use them exactly at the point of output, and hence in a contextual manner. Instead, if you allow escaping arbitrary elements (arrays, objects, etc) then the contextual guarantees disappear, as well as pushing the escaping further from the point of output. This makes it harder to actually verify and reduces the overall security. Not to mention that it makes the API a lot harder to follow and a lot more "magic". Both of which are clear negatives on a security sensitive API. ------------------------------------------------------------------------ [2015-06-23 09:39:10] yohgaki@php.net I can take care of them also. I also notice that current php_html_entities implementation is not optimal. It can take 1st parameter as zval and convert int/float simply to string. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=69908 -- Edit this bug report at https://bugs.php.net/bug.php?id=69908&edit=1

« previous php.bugs (#229937) next »