Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87403 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22398 invoked from network); 30 Jul 2015 15:20:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Jul 2015 15:20:20 -0000 Authentication-Results: pb1.pair.com smtp.mail=craig@craigfrancis.co.uk; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=craig@craigfrancis.co.uk; sender-id=pass Received-SPF: pass (pb1.pair.com: domain craigfrancis.co.uk designates 209.85.212.179 as permitted sender) X-PHP-List-Original-Sender: craig@craigfrancis.co.uk X-Host-Fingerprint: 209.85.212.179 mail-wi0-f179.google.com Received: from [209.85.212.179] ([209.85.212.179:37405] helo=mail-wi0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A6/00-21759-1B04AB55 for ; Thu, 30 Jul 2015 11:20:17 -0400 Received: by wibud3 with SMTP id ud3so73015499wib.0 for ; Thu, 30 Jul 2015 08:20:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=craigfrancis.co.uk; s=default; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=k51HOHap6206BZ2UBKSYPPBbk959gI6yJ7hTLSALnS4=; b=YA8bV71ZsjzF65NL/kCWyPNd8JhkFYbqN7SNd/oCzTGvqirwp7j0TyyBkarociLDcC LHtJEuiuQscajhV2cklsdiuoe+U1eoydIk+VtMCErsEF18/7tQmIw5RJ2oE1BAxhFQbZ awcGQ+lqKoyBI2q3C7Lxus43PzvikgNY911OM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:content-type:mime-version:subject:from :in-reply-to:date:cc:content-transfer-encoding:message-id:references :to; bh=k51HOHap6206BZ2UBKSYPPBbk959gI6yJ7hTLSALnS4=; b=bLGdic75+EbcmhdKezAFehzu04sP11PhEnYfPPLgnitsqXN5o4GM9nrgxnWn290qc6 5VLhVoxOSnQF4ehVOi8b4kMmkLzMfw+f2HQ1+9Uf11Jm+GtEcwKTR3DabeXb50icdkRk nVYcCSoyD8oAz5gWJRPmwmsTifbn6gPhGhoLsI4ckQ0Jqjt5Hgqlje+zuSycHcV4dRyk /Tq+0JF6TRtqgO9Feo+uQn/LH7hfU0YqxsLDKG9Rm40Hc6bo55ywloTXsGBXAEp3Luys nuR0KQFGpORdC9mM/p63GHtmDA/WBs14nXu/avTu3DMNeLabvJdorbv8WZzJNVlKP+/r mi/g== X-Gm-Message-State: ALoCoQl7u6Nq+IjMd1Acn0jz3H0oRZ1us/dZ5MEpqJELjuct3HGCE/6Fo02KrlxIn6cohWvAZFlq X-Received: by 10.180.36.16 with SMTP id m16mr7242564wij.26.1438269614395; Thu, 30 Jul 2015 08:20:14 -0700 (PDT) Received: from [192.168.1.12] (cpc4-chap7-2-0-cust64.aztw.cable.virginm.net. [92.233.53.65]) by smtp.gmail.com with ESMTPSA id r19sm3557761wib.7.2015.07.30.08.20.13 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 Jul 2015 08:20:13 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) In-Reply-To: Date: Thu, 30 Jul 2015 16:20:12 +0100 Cc: Joe Watkins , Lester Caine , PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: <67D5FE0C-3919-4695-B836-E1B9A553F0E4@craigfrancis.co.uk> References: <55B896B8.4070901@lsces.co.uk> <6F8B9B35-D487-45D9-BC84-4A782951EDC7@craigfrancis.co.uk> <55B9D14B.9010902@lsces.co.uk> <44415028-F437-4914-818C-C928BA01D7FE@craigfrancis.co.uk> To: Xinchen Hui X-Mailer: Apple Mail (2.1878.6) Subject: Re: [PHP-DEV] [RFC] Block requests to builtin SQL functions where PHP can prove the call is vulnerable to a potential SQL-injection attack From: craig@craigfrancis.co.uk (Craig Francis) On 30 Jul 2015, at 13:47, Xinchen Hui wrote: > anyway, with PHP7's new zend_string, and string flags, the > implementation will become easier. Hi Xinchen, Glad to hear that you are still looking into this... please let me know = if there is anything I can do to help (unfortunately I'm not a C = programer). Out of interest, if you are going to continue using "taint_marks", as = the RFC suggested... can I suggest all variables start with 0 (or = undefined)... then you can set flags as the variables are passed though = functions like htmlentities and pg_escape_literal? This way all variables are treated as plain (unsafe), and then = developers either need to escape them (e.g. when printing to output, or = using in SQL, CLI, etc), or they can mark them as having already been = escaped (rare). Likewise, I know you have examples that say "SCRIPT_FILENAME" is safe by = default (I kind of disagree)... it would still be advisable to encode = them, even if they are being included in the HTML... personally I would = not have any variables marked as safe by default (with the single = exception of strings that are defined in the PHP code itself). Craig On 30 Jul 2015, at 13:47, Xinchen Hui wrote: > Hey: >=20 > On Thu, Jul 30, 2015 at 8:14 PM, Joe Watkins = wrote: >> I find myself agreeing with Pierre; The wrong signal would be sent. = History >> should teach us there is no such thing as (a) safe mode. >>=20 >> Xinchen did used to work on a taint extension, I wonder why that was >> stopped ? > yes, it is https://github.com/laruence/php-taint >=20 > Anyway, I was too busy so I didn't make it supports PHP-5.6, I was > hoping someone could help(it supports 5.5 now). >=20 > it is a complex extension, and using tricky way to keep taint infos >=20 > anyway, with PHP7's new zend_string, and string flags, the > implementation will become easier. >=20 > I have a plan to make it supports PHP7.. >=20 > thanks >>=20 >> Worth noticing that the extension is rather complex, touching many = parts of >> the engine, changing many things ... which I don't really like. >>=20 >> Cheers >> Joe >>=20 >> On Thu, Jul 30, 2015 at 10:14 AM, Craig Francis = >> wrote: >>=20 >>> On 30 Jul 2015, at 08:24, Lester Caine wrote: >>>=20 >>>> But that is a perfect example of what I am talking about. You do = not >>>> educate people by publishing the very thing that is wrong. You = educate >>>> them by pointing out to them WHY the '?' was there in the first = place. >>>=20 >>>=20 >>>=20 >>>=20 >>> I completely agree on education, and what I'm hoping for... and this = is >>> how we can educate everyone :-) >>>=20 >>> My suggestion for taints (not quite the same as the one from Matt or >>> Wietse) was not to change the way good programs are = created/executed, but >>> simply an education device, which can also pick up mistakes that >>> experienced developers make. >>>=20 >>> While my first post on this mailing list gives a better overview: >>>=20 >>> http://news.php.net/php.internals/87207 >>>=20 >>> The original implementation suggestion is at: >>>=20 >>> https://bugs.php.net/bug.php?id=3D69886 >>>=20 >>> You will see that it does nothing more than create notices to say = "erm, do >>> you want to be doing this?". >>>=20 >>> This is something that only PHP can do, unless you can find a way of >>> changing every single article / code example on the internet :-) >>>=20 >>> So, with your example... if you want to use a variable for a = table/field >>> prefix, that is perfectly fine... in fact, it won't need any = changes, as >>> the prefix will probably be hard coded as a string within a PHP = script >>> (something I called ETYPE_CONSTANT). >>>=20 >>> But if not (e.g. storing the prefix in an ini file?), then I've = shown an >>> example of how that can be handled with the proposed = "string_encoding_set" >>> function (something I should have probably called = string_escaping_set)... >>> which is simply to tell PHP that this one variable is already safe >>> (something I can't see being needed very often). >>>=20 >>> Craig >>>=20 >>>=20 >>>=20 >>>=20 >>>=20 >>> On 30 Jul 2015, at 08:24, Lester Caine wrote: >>>=20 >>>> On 29/07/15 16:11, Craig Francis wrote: >>>>> I completely disagree... prepared statements are just as = vulnerable, >>> and so are ORM's. >>>>>=20 >>>>> You can push developers towards these solutions, and that would be >>> good, but you are completely blind if you think an uneducated = developer >>> won't do: >>>>>=20 >>>>> if ($stmt =3D $mysqli->prepare("SELECT District FROM City = WHERE >>> Name=3D" . $_GET['name'])) { >>>>> } >>>>=20 >>>> But that is a perfect example of what I am talking about. You do = not >>>> educate people by publishing the very thing that is wrong. You = educate >>>> them by pointing out to them WHY the '?' was there in the first = place. >>>>=20 >>>> Since the taint extension only covers mysql and sqlite it's of = little >>>> use if we manage to convert 'uneducated developer' to any of the = more >>>> secure databases, and that was one of the reasons why mysql was = dropped >>>> from being loaded by default. Once one starts from a base of >>>> parametrised sql queries the lax programming methods many mysql = guides >>>> and books continue to push can be reversed. Throwing more bloat = into php >>>> to create 'WTF' errors just adds to a new users frustration and = annoys >>>> experienced users who have very good reasons for building queries = using >>>> clean variables. MANY abstraction layers use variables to add = prefixes >>>> to table names or fields. >>>>=20 >>>> Educate ... don't nanny ... >>>>=20 >>>> -- >>>> Lester Caine - G8HFL >>>> ----------------------------- >>>> Contact - http://lsces.co.uk/wiki/?page=3Dcontact >>>> L.S.Caine Electronic Services - http://lsces.co.uk >>>> EnquirySolve - http://enquirysolve.com/ >>>> Model Engineers Digital Workshop - http://medw.co.uk >>>> Rainbow Digital Media - http://rainbowdigitalmedia.co.uk >>>>=20 >>>> -- >>>> PHP Internals - PHP Runtime Development Mailing List >>>> To unsubscribe, visit: http://www.php.net/unsub.php >>>>=20 >>>=20 >>>=20 >>> -- >>> PHP Internals - PHP Runtime Development Mailing List >>> To unsubscribe, visit: http://www.php.net/unsub.php >>>=20 >>>=20 >=20 >=20 >=20 > --=20 > Xinchen Hui > @Laruence > http://www.laruence.com/