Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79020 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 25440 invoked from network); 20 Nov 2014 07:30:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Nov 2014 07:30:30 -0000 Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.174 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.223.174 mail-ie0-f174.google.com Received: from [209.85.223.174] ([209.85.223.174:43150] helo=mail-ie0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 56/B1-14967-4989D645 for ; Thu, 20 Nov 2014 02:30:28 -0500 Received: by mail-ie0-f174.google.com with SMTP id rl12so2172497iec.5 for ; Wed, 19 Nov 2014 23:30:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=dPDRyCdxeKrE/40MC0ONMl435fYbtx0U1ZWXzTbezu4=; b=u6sRoBBaYdoYmfNHpUf0O/eRYn6GKfnbVPcoKfVodlvuRAkdaGpPBh+QPy0QU0kNGp Kw/tbCbjibxm4uGzgzNG8Ti1sfTYQurOwja6zII+wIbH562uJjY7TbsxvNdArpGI14cQ t/4espTErUIlN2guqXNv/dlc2bjp5XDAZJbb7pq7G/K9UOg8knZDEq3cZCUw1nNbeMaB MndvxxXltsPAEPD5Pw7mSa1YDhH1DzL9Va/K5zRhXzwckMJ70AmigIsnLVxGg7tBF6+3 uNPBd0JClBTmpu4Um4adPZVH7PsAI6XJDR7Ssidg3D1dLoHKQqYrCeUSFaBriFLTmbST NR8w== X-Received: by 10.42.230.15 with SMTP id jk15mr77910icb.55.1416468625245; Wed, 19 Nov 2014 23:30:25 -0800 (PST) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.107.164.217 with HTTP; Wed, 19 Nov 2014 23:29:45 -0800 (PST) In-Reply-To: References: <66B7B28C-2651-4A71-AC2A-55D4C7BB3DDC@ajf.me> <546D43B3.60708@gmail.com> Date: Thu, 20 Nov 2014 16:29:45 +0900 X-Google-Sender-Auth: N2FlnqOlFBhsoneJWgFWgkqG6H0 Message-ID: To: Stanislav Malyshev Cc: Andrea Faulds , PHP Internals Content-Type: multipart/alternative; boundary=001a11c35e343e4f420508454d77 Subject: Re: [PHP-DEV] [RFC] Safe Casting Functions From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a11c35e343e4f420508454d77 Content-Type: text/plain; charset=UTF-8 Hi Stas, On Thu, Nov 20, 2014 at 4:10 PM, Yasuo Ohgaki wrote: > Please refer to CWE/SANS TOP 25, Monster Mitigation especially. > > http://cwe.mitre.org/top25/#Mitigations > > and ISO 27000. (I cannot provide link to it, since one should buy the > document to read) > > Programmer should control over all inputs as the most important security > measure. > There are two strategies in general. > > - Convert inputs to secure values and ignore possible attacks. > (Sanitization) > - Validate inputs to reject malformed values and record possible attacks. > (Validation and logging) > > (int) is sanitization. It works, but it cannot log/detect possible attack > (or bug). > > to_int can be used as validation. It has advantage to record possible > attack (or bug). Logging is > one of important security feature. Therefore, validation could be said > more secure than sanitization. > > Which strategy to adopt is that depends on organization/application > policy. Public web sites may ignore > invalid inputs due to large amount of attacks while private web sites may > require to record all > possible attacks (or bugs), for example. > We know people do things like $id = $_GET['id']; pg_qeury("SELECT * FROM some_table WHERE id = $id;"); (int) works mostly. to_int is better as it may detect possible attack or bug. I implement user error/exception handlers always to detect possible attack/bug. to_int may be used as validation to detect internal logic inconsistency as well as user input validation. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a11c35e343e4f420508454d77--