Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94532 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91936 invoked from network); 17 Jul 2016 14:47:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Jul 2016 14:47:54 -0000 Authentication-Results: pb1.pair.com smtp.mail=michael.vostrikov@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=michael.vostrikov@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.182 as permitted sender) X-PHP-List-Original-Sender: michael.vostrikov@gmail.com X-Host-Fingerprint: 209.85.216.182 mail-qt0-f182.google.com Received: from [209.85.216.182] ([209.85.216.182:33419] helo=mail-qt0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 30/97-31884-89A9B875 for ; Sun, 17 Jul 2016 10:47:53 -0400 Received: by mail-qt0-f182.google.com with SMTP id w38so81168457qtb.0 for ; Sun, 17 Jul 2016 07:47:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=apZIHV45Z3PC9ORFV2AsT39bLfzX3XpnBKFPywj0PoE=; b=wFQwGyqis11efD5dWtP6dDYexL9gQ3xDYDG4L4uA/ZPNre3Bfq5IQHjQ94uhgBwW2f +S9CA9OiL/tT8/K8SpSTfpO7ws3ZgRvQNf5y7xV4jg4q1UmII2H8q3leLphOtWhUTBkQ tOlQerT436+xM15rB8iwZnWxndokXIHyUbr8I2tOCTyDlBIAHP5A5jhi337rHDuHwXGk ZVIjA2q/94E7+zwKNhh5S5zj+fr4n7BJZoLU2YU46IvHYH9xSByoAvMwzWchhg+XolZH 1nLJFdtL/kY+NVDD3UtEqOVJBUlgsf3dGNdwAEeh0H0hUp57gyqbwsl1cC/slw8ysMKH rA8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=apZIHV45Z3PC9ORFV2AsT39bLfzX3XpnBKFPywj0PoE=; b=gnBw+zsngS8JfNVZ2JBho/F9fKg6MzsrnXaQU1r0DxRvGtTOVVBDghawF3dltHpNhz ULqZv8qIefsOHj3e5z97l+DUhOHpAZv5gPqX8jjbV4IkBGMh0NJi+wqofArJkHONev5n Rc4wJuzUlsdKjSVVyVQVAaHBz0i7wT+m95A8Efr8qrcSVcJtutuOkplsMS/qKyeAJZsB wEwHcKRyroUrQeQIVf0rRRLGnMdORo6h/nXbu9PDlBEO5RzH/SZoNvyK0VgEBmQXdwCh myL81NkbI2XvLLOIqeu613Ti7aHEdZLxKL7aVeWJ4S6WRsRNFicwXP6efCPiLQbrawus GYtg== X-Gm-Message-State: ALyK8tKZXg0u+/Xh5CKMlS4QJn347Iyuc/MNtMpZ0iQuIXCzCYrtQfy5MgTLjVW8ayq9SSuspePiKO6Gh4jkHg== X-Received: by 10.237.36.38 with SMTP id r35mr45704543qtc.3.1468766870231; Sun, 17 Jul 2016 07:47:50 -0700 (PDT) MIME-Version: 1.0 Received: by 10.55.189.135 with HTTP; Sun, 17 Jul 2016 07:47:49 -0700 (PDT) In-Reply-To: References: Date: Sun, 17 Jul 2016 19:47:49 +0500 Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary=001a113d3aac8ee27c0537d5efa7 Subject: Re: [PHP-DEV] [RFC] New operator for context-dependent escaping From: michael.vostrikov@gmail.com (Michael Vostrikov) --001a113d3aac8ee27c0537d5efa7 Content-Type: text/plain; charset=UTF-8 > > All it is, really, is a registry for functions, and syntactic sugar for > calling those functions - it's unnecessary, it's more global state you have > to manage and it's the kind of superficial convenience that will end up > breeding more complexity. > Registry of functions - is exactly how escaping is performed in Symfony and Twig. https://github.com/symfony/symfony/blob/f29d46f29b91ea5c30699cf6bdb8e65545d1dd26/src/Symfony/Component/Templating/PhpEngine.php#L421 https://github.com/twigphp/Twig/blob/f0a4fa678465491947554f6687c5fca5e482f8ec/lib/Twig/Extension/Core.php#L1039 What's also strange, is the ability to call functions in this registry > hinges on syntax. What if I want to call the registered functions from > within code? > ob_start(); > ?><* $text *> $html = ob_get_clean(); > Sorry, I don't understand what do you mean in this example. You can call your escapers by name or by callable value from array of handlers. <* $text *>" // -------- ob_start(); ?> > Both variants and work good. > This is so true - and the whole syntactic convenience line of thinking > really should end with that. > Wrong and unsafe variant should not work good. > Also there is a problem with function autoloading. > I maintain that this is the real problem, and perhaps the only problem - > all this RFC does, is provide a stop-gap solution. > This RFC is not related to function autoloading. It just does not have this problem. The code becomes the same as if we will write PHPEscaper::escape() manually. In the static calls there is no problem with autoloading. It's somehow easier to choose between two different characters * and = > versus electing to call a function or not? > Unsafe variant 'not to call a function' is a short subset of safe variant 'call a function'. Safe variant requires additional actions. With new operator safe variant is as easy as unsafe. And we must not choose, operator must be used everywhere, except 1-2% of cases where we have ready HTML. And if we accidentally use it for HTML, this will not be an XSS, it just will show double-encoded content, and this will be noticeable. All this RFC changes is the syntax - not the problem. > Ok, what do you think is the problem? As I think, the problem is correct HTML escaping and XSS. And it can be solved the same way as in template engines. I don't suggest to bring the whole template engine into PHP, only escaping mechanism. Function autoloading - is another problem. Addition of a feature like this will affect even those who don't use it > It does not affect any existing code. It is not a replacement for operator. a feature like this will bring global state, side-effects and many other > interesting problems > Default implementation of PHPEscaper is not required. This is possible to fully remove it and use custom PHPEscaper written on PHP. Or just don't use this operator and don't worry about escaping. Ok, could you please give an example of the problem? when they inherit or consume code that does > I think this is the same as if they inherit or consume code that uses Twig or Smarty. you're asking specifically about the proposed feature, rather than asking > in general about the problem > The proposed feature solves the problem with HTML escaping. I asked about presence of problem and about a solution. Also, in the previous discussion I got the first answer that "Main issue with this kind of proposals is that escaping is context-dependent". This issue is mentioned in many other discussions. And I suggested a solution for this problem too. And that's why I asked about an official poll in the first message of this discussion. This is a serious change and we need to know community opinion about it. reasoning about the impact on the language, or deeper problems requires > more of an involvement > And RFC is intended for this, isn't it? Could you give an example of impact which can bring the problems? > More than 90% of output data - is data from DB and must be HTML-encoded > Yet, you argue we need a function registry for all kinds of other escape > operations to address the other 10% > Hm, wait please. Initially I suggested an operator specially for HTML escaping. I tried to demonstrate that this is special context and it deserve its own operator. I got the answer that there are many other contexts and making an operator for one context is a bad idea. Ok, I suggested the solution which allows and HTML escaping, and usage of other contexts. Let's define, what is more suitable - many contexts or one context. you argue we need a function registry > Function registry is just a default implementation of PHPEscaper class. It can be used 'out of the box' and provides HTML escaping by default. Default implementation can fully be removed from the project, and replaced with custom implementation - e.g. with limited set of methods. There is just one static call, which does not differ from function call, but allows autoloading. which could be more generally addressed by solving autoloading > I can only repeat that the problem is not that we don't have a function. We have a function and can write own functions. Maybe there are little issues with direct usage of static class method, but it can be solved by defining a function in global namespace, which will call this method, as it is done in some frameworks. Please, let's focus on improving the language in general - rather than > improving one isolated use-case. > Why do you call 90% of output data a 'one isolated use-case'?) I can only mention here the words which were shown to me when I created the RFC: Quoting Rasmus: PHP is and should remain: 1) a pragmatic web-focused language 2) a loosely typed language 3) a language which caters to the skill-levels and platforms of a wide range of users HTML escaping is a very pragmatic task. --001a113d3aac8ee27c0537d5efa7--