Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94710 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72931 invoked from network); 26 Jul 2016 13:14:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Jul 2016 13:14:22 -0000 Authentication-Results: pb1.pair.com header.from=michael.vostrikov@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=michael.vostrikov@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.173 as permitted sender) X-PHP-List-Original-Sender: michael.vostrikov@gmail.com X-Host-Fingerprint: 209.85.220.173 mail-qk0-f173.google.com Received: from [209.85.220.173] ([209.85.220.173:35113] helo=mail-qk0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0E/01-63332-C2267975 for ; Tue, 26 Jul 2016 09:14:20 -0400 Received: by mail-qk0-f173.google.com with SMTP id s63so5268572qkb.2 for ; Tue, 26 Jul 2016 06:14:20 -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:cc; bh=s8ug33u57UN/Ftirk5ekMjwt3h1f2WkjTe/VX4qshq4=; b=Xd9JitYA6uRC/QkgozZxtSV7Vkw8sme26qfe531eRsuAiFU6K6SRU00tY8JMGHd2GY SHHDuMxNFPHKp4Ppp6yUx3zUFGv4mN+DjOqEVQ1sAKPbYC0tM4l++TN4kz5/tN+1Cxq3 9TJWtxIvxp805PQMRUDJsSU+vbINRZ5zLEDjIyOcKEtni/NLCs7/0vnQSiA0H7z3Ezab Ca9CmLn4U0w2D4n1lMjWCqvDFneCNWzMzGTjdmFXQ2DC7qxQBSebA6rq2TYVcIzetzfL 0Cp7xP/4McAXXxU8vOpnRLvQnqt93KS3Z5CrECGUlW/V4hJ/d1Eksx/3ggL+h86JKcEE xbeQ== 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:cc; bh=s8ug33u57UN/Ftirk5ekMjwt3h1f2WkjTe/VX4qshq4=; b=Fy0EmDTA9RjHPpz2WHTbO3KES4Utb3XTX5xgkwgSmE4GY/a1PIcQ8jEaYWmnR6oaJT zWPR9MGmw77GSjPnk3+J+gU2GrcV9AjYATvwpfzAZSiaiG6SXoLFw9+y7dEeljEXY0Wp lRgkk01hXY4b4k9VaBSXEpJurt1852RnqRMD75Kvae+2lOwJJZEWpzc6Lb2aRJ+0XC+k 4iXDiQ67rlZ/Ek4iC+F3+u9EQQ49EkNi6q+Nxhpo6I40b4Gkg5mR1goADidEZBgtBQ/Y iQ1URasoJGWtZKIC/VsA4YpAaEjTyRB+6zodX4G3ggfCp6KXOJ757ySHlRgYk8mTS9Rs cL3A== X-Gm-Message-State: AEkoouux9t31KrbY8SjGNYqXjUHwA8KKY/mFqKdYbWXxHXDvKF6QfqnILF3xv7AP/mpax4NQaF4AnnUMLUM3IA== X-Received: by 10.55.74.138 with SMTP id x132mr29562110qka.26.1469538857293; Tue, 26 Jul 2016 06:14:17 -0700 (PDT) MIME-Version: 1.0 Received: by 10.55.189.135 with HTTP; Tue, 26 Jul 2016 06:14:16 -0700 (PDT) In-Reply-To: <9bc0db6a-fa19-5f87-0e82-3702dcb34254@gmx.de> References: <8a39df34-4a23-c496-15f6-20a62d27fc59@gmail.com> <4920f683-9a4d-7153-b157-a7d7ce8cbfe7@gmail.com> <933449d0-90c2-0d7a-cb80-a171289d8286@texthtml.net> <20160724145557.D52C31A80BBD@dd1730.kasserver.com> <6cfac572-9982-87f8-5a55-9213d978cde9@gmx.de> <20160724162103.BC5741A83512@dd1730.kasserver.com> <20160724172131.675AC1A800B0@dd1730.kasserver.com> <9bc0db6a-fa19-5f87-0e82-3702dcb34254@gmx.de> Date: Tue, 26 Jul 2016 18:14:16 +0500 Message-ID: Cc: PHP Internals Content-Type: multipart/alternative; boundary=001a114a82f892a2d4053889ad6b Subject: Re: [PHP-DEV] [RFC] New operator for context-dependent escaping From: michael.vostrikov@gmail.com (Michael Vostrikov) --001a114a82f892a2d4053889ad6b Content-Type: text/plain; charset=UTF-8 > PHP today is a programming language, and applications and libraries can be and are written in that programming language. PHP has and tags, all outside these tags is considered as HTML. It is needed or to remove these tags and use PHP as programming language only, or to improve usage of these tags. Because tags itself without additional handling causes XSS vulnerabilities. > Trying to build default functionality that would compete with a modern templating engine like Twig would be a lot of effort, and to what end? A kind of language nationalism, that "PHP does it all"? This operator (or tag) is intended for that applications which are already writte and already do not have template engine, but are developed and require to write code. Also, there are frameworks or CMS, which do not have built-in template engine, and people start new projects using them. Also, this operator can be useful for junior programmers, who know PHP but don't know some template engine yet. > register_escape_handler('foo', [$this, 'escape']); > > Where's the problem? > If you mean you want to be able to pass an actual callable as the context No problems with the code, I anwered to "IDE will have problem by identify where you have defined it". I did not mean a callable as a context. > it doesn't really matter if you say the incantation to output a variable is "", or "". It does matter. He can try to remove unnecessary 'e' and see that it still works good. With old operator he can write unsafe code without additional actions. With new operator he should specially set 'raw' context or something similar. This is the reason why template engines have html escaping by default. > One is 3 characters shorter, but that is the sole difference in terms of effort. No. The difference is that you cannot write unsafe code by removing 3 characters. Length of code or function name is not the reason of this RFC, I told this many times. > Huh? Is the word "I" copied in this e-mail, because the English language requires me to write it more than once? And if "e(" is "copied code", how is the "*" in " is one action in source code, are 2 actions. This is the same as if you woul need to call constructor manually every time: new MyClass->__construct(). Is it a better code? Maybe let's remove automatic constructor call?) > Twig allows you to register a named "strategy" to a single callable, exactly as I am suggesting: http://twig.sensiolabs.org/doc/filters/escape.html#custom-escapers This is much more useful than a single callback that has to handle all possible strategies. As I understand, the problem is that this is a registry with global state, as Rasmus said. In Twig this is not a global registry, it is stored in object of 'Core' class. And yes, this is a single callback twig_escape_filter(), which handles all possible strategies. First variant of this RFC was a registry. But actually, people don't need a registry, especially with built-in escapers, they ask about an easy way to call escaper (htmlspecialchars() in feature requests). Also, all possible strategies depend on tasks. Even for htmlspecialchars() different set of flags could be used. Let user choose how to escape HTML. This is needed once during application development. > But this could still be done without allowing arbitrary expressions, or embedding syntax inside the strategy argument: > Sorry, I don't understand. Why $strategy is not 'arbitrary expression'? And why it is needed to make so complex parsing logic, which will be the same as html($text, $strategy)? > If they're doing something complex, they can implement their own way of doing it - probably by writing a templating engine, or using one of the many that already exist. There is a possibility to make this with new operator describeed in RFC. It does not require many changes in PHP source code or application source code. Why it is needed to specially restrict its functionality? > So it is now mandatory to have some bootstrap file somewhere that defines and registers the escape function? How is that different from writing, right now, at the top of your bootstrap file: > function e($str, $context = 'html') { ... } It is different, because this function must be called everywhere manually, and when it is missed, this gives a possible XSS vulnerability. New operator is a simple way to automatically call user-defined escapers. >> Complicated syntax like . > I have no idea why that is "complicated syntax", but your proposal isn't: > > Or even: > That is "complicated syntax" because it requires many changes in the syntax parser, more than operator described in RFC. More changes - more complexity. And I don't suggest multiple arguments. > In your proposal, part of the syntax won't even be standard between different people's code There is no aim to invent new global standard. As there is no standards for naming escapers function, they are differs in different people's code. > Is it just that you don't like the escape strategy coming first? I told about flexibility, not about placement. >> I.e. we anyway need to pass context as a second argument, so why not allow user to do it. > Because we're trying to make it easier for the user, not harder. Why restriction is easier? You decide to forgive pass a context as a variable, and user > Why make them handle the nesting, sanity-checking, and control flow of multiple filters, rather than building them into the syntax from the start? Because this fully depends on application, which flags should be passed into htmlspecialchars. So, user must first unregister build-in handler and then register his handler. --001a114a82f892a2d4053889ad6b--