Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:63178 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69027 invoked from network); 20 Sep 2012 03:25:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Sep 2012 03:25:29 -0000 Authentication-Results: pb1.pair.com smtp.mail=davidkmuir@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=davidkmuir@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.42 as permitted sender) X-PHP-List-Original-Sender: davidkmuir@gmail.com X-Host-Fingerprint: 209.85.160.42 mail-pb0-f42.google.com Received: from [209.85.160.42] ([209.85.160.42:40037] helo=mail-pb0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BA/FB-15057-7AC8A505 for ; Wed, 19 Sep 2012 23:25:28 -0400 Received: by pbbrp8 with SMTP id rp8so3995594pbb.29 for ; Wed, 19 Sep 2012 20:25:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=UMGg8We60OFEbaLTp3vgz99mpuWfg7bYETmP5PPkIwM=; b=aXehGjWjFSsPcsqNTABSlCxDysKJkabRpKj20N+bT937L43QeOw17jyENBQpPttlAN fvf0w0pn00jN09tYIyZZGUq378HHr++IjQq5/nmN7Pq77R4NPTlQaSPkvDfB5HDAB5hJ sfOwbEKd7IX7OgV8IQmOr4aOiQQgGmFfEV3+7OQLeXjm6VcAImBtWC4i91+MJB7ueOnJ sNd6vC+hqMC+F497QFvdfU4JK4QjqWRQQzeX9XSHz6cBKOosoHBdU3hfBYw+CxKd8YOF 3u2ZQulJFwylbDEookdx1q6xmKb+e5OPbn2S4bQzOgAwUK5RbKQUzLdKEG4IkHACknYf XImg== Received: by 10.68.222.37 with SMTP id qj5mr2915505pbc.132.1348111524561; Wed, 19 Sep 2012 20:25:24 -0700 (PDT) Received: from [192.168.1.181] (tmwpho1.lnk.telstra.net. [110.142.207.74]) by mx.google.com with ESMTPS id bj7sm1712199pab.24.2012.09.19.20.25.22 (version=SSLv3 cipher=OTHER); Wed, 19 Sep 2012 20:25:23 -0700 (PDT) Message-ID: <505A8CA3.50101@gmail.com> Date: Thu, 20 Sep 2012 13:25:23 +1000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120827 Thunderbird/15.0 MIME-Version: 1.0 To: Michael Shadle CC: =?UTF-8?B?UMOhZHJhaWMgQnJhZHk=?= , "internals@lists.php.net" References: <0AC6EB13-3588-403B-BE73-968F12C7B7AF@gmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] RFC: Implementing a core anti-XSS escaping class From: davidkmuir@gmail.com (David Muir) On 20/09/12 07:48, Michael Shadle wrote: > On Tue, Sep 18, 2012 at 10:32 AM, Pádraic Brady wrote: >> Hi Michael, >> >> See the link near the bottom of the RFC - even htmlspecialchars() has >> unusual behaviour that's potentially insecure. I have no objections to >> there being functions, of course, and the RFC makes that clear. >> However, many programmers like me are obsessed are objects so having >> an SPL class will obviously be near and dear to my design patterned >> heart ;). > After looking over the RFC finally, would it be that crazy to consider > this an extension of the standard string functions? > > str_escape($string, $encoding, $flags) or probably better > str_escape($string, $flags, $encoding) - since encoding could be > defaulted to UTF-8, but flags are really what differentiate the > behavior... > > Then there is not a handful of functions but rather one that can be > used as the abstraction point and the flags passed to it will change > it's behavior, much like the filter functions. > > (I just see this falling under one solid defacto escape function > standard, and it could live by itself as "escape" or something, or as > it operates on strings, prefix it as such) > I'm on the fence with a default encoding. I tend to always use UTF-8, so would probably just use the default. But that means I become less aware of encoding being central to the issue, and therefore much easier to accidentally leave it as UTF-8 when it should be something else. -1 on the flag based api, though. Would much rather have dedicated functions. It's easier to read, and less verbose.
escapeHtml($foo)?> escapeHtml($bar)?>
I prefer the OO API since it's succinct, but if we are to have a procedural API as well, lets make it concise and clear. The last thing we want for solving the no 1 security threat to web-apps is a confusing and hard-to-use API like the filter extension. Cheers, David