Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:42240 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 23023 invoked from network); 13 Dec 2008 21:44:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Dec 2008 21:44:26 -0000 Authentication-Results: pb1.pair.com header.from=thetaphi@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=thetaphi@php.net; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 80.190.230.99 as permitted sender) X-PHP-List-Original-Sender: thetaphi@php.net X-Host-Fingerprint: 80.190.230.99 www.troja.net Linux 2.5 (sometimes 2.4) (4) Received: from [80.190.230.99] ([80.190.230.99:47453] helo=mail.troja.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 99/6B-47862-9BC24494 for ; Sat, 13 Dec 2008 16:44:26 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.troja.net (Postfix) with ESMTP id 90A844E65B; Sat, 13 Dec 2008 22:44:22 +0100 (CET) Received: from mail.troja.net ([127.0.0.1]) by localhost (cyca.troja.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 06282-06; Sat, 13 Dec 2008 22:44:21 +0100 (CET) Received: from VEGA (port-83-236-62-11.dynamic.qsc.de [83.236.62.11]) (using SSLv3 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.troja.net (Postfix) with ESMTP id ABC3D4E5DD; Sat, 13 Dec 2008 22:44:20 +0100 (CET) To: "'Mark Karpeles'" , "'PHP Developers Mailing List'" References: <2D85B33E-889B-4214-9BB8-A12EFFFC641E@macvicar.net> <1229150500.30719.201.camel@localhost> Date: Sat, 13 Dec 2008 22:44:20 +0100 Message-ID: <4BA26FE8A9634178B4CEBEFA818810D2@VEGA> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 Thread-Index: Aclc7fCTghJ2p56TT/q6Lq8wkdUY/QAfQpUw In-Reply-To: <1229150500.30719.201.camel@localhost> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 Subject: RE: [PHP-DEV] Removing basic types from our JSON parser From: thetaphi@php.net ("Uwe Schindler") > For reference I saw people use json_encode() to pass a string to > javascript into their page while avoiding bugs/XSS with stuff like > . > > var foo = ; > ... (yes, they maybe heared somewhere that JSON is *not* javascript, I > told 'em too). This is not correct. JSON *is* valid JavaScript, but the other way round is not correct. Not every Javascript is JSON. So it is perfectly legal, to do this. I think, this is really cool, using json_encode() as something like "htmlspecialchars" for correctly encoding strings inside JS for security. I use it, too. To the problem with basic types: I like the way of maybe giving a option to the function. If you want to be standards conformant, you have to remove the encoding parameter (which is also there), too. JSON has to be UTF-8, if you want to be conform to the specs. But for the example above (secure encoding of JS strings with json_encode), it is perfectly legal to use another encoding (in the above case, the encoding of the HTML page). Uwe