Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:95780 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87376 invoked from network); 8 Sep 2016 09:04:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Sep 2016 09:04:30 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.66 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.66 mail-wm0-f66.google.com Received: from [74.125.82.66] ([74.125.82.66:36272] helo=mail-wm0-f66.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 07/A4-36123-D9921D75 for ; Thu, 08 Sep 2016 05:04:29 -0400 Received: by mail-wm0-f66.google.com with SMTP id l65so6808958wmf.3 for ; Thu, 08 Sep 2016 02:04:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:references:from:to:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=tRIMDIuykIo77Maie21yhyRijPfUBEFZMPqsGEhjbdA=; b=Yc4g7VQv5s617/+j29sMTQ4sscAZ2GdkMaEhFtFDBIBsL3a0EUHLMGzWYNIbM6zWV9 poFbVmE6T0nYboKzdTeNrdHLRsysee5xm3guLmrmpk6V4vRKhnyLRdGbbelxS+JS4W+/ oo4H79G40aELxxa9Gx4OriDTYh79RiTUsIRPRxcuW9CMigLTTQFMik9KWDhKdqxeLnwM zt9S/Ojjt/4xvdHYURe6bI6u8SuBIK8kiLXtx6J8+nljSIvnkFjYAaVeOumevZZk5vVI opF0S+EryL1E4KtzmsiW6Ig0bEL9XSgMGW6fUIkZYl81cXgCMScod1y9Sa1MOaMxL00w UiUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:references:from:to:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=tRIMDIuykIo77Maie21yhyRijPfUBEFZMPqsGEhjbdA=; b=AsaICEbFVv5nFfmhEPAwRai8hLKWlms/v+KUBVNqWR+1o05+xlZNyZ68vnkaYwGNCX HW7Nt0Bk7s/k4F2FrtI2opnOqP7W+inJaz1/hDRbZ2MChqRcNoE6k3DzrTm58t/3Iveb aY7Myq8bLlMMub3+R6TQgAhWq2fGwl4C3/hcGpdANZCTzc3ANZbwBmeMwmCeiJCKAaTf 3dqF8bVRkztMhgJOP2NJJUCba8KiVQ4k6AtMpTMjtjpkc2ARVs2ilVbmOea3o9TOe0ir XyEeWId1ySjP1RMakBIis9hsf6Qqt3v5wKZrqrxbD3v88t0A5MbCaJ33hgewz3ZaxWqb AdOA== X-Gm-Message-State: AE9vXwNUYiMRbNNx662XXsyM6YInYRCZpbSUCrt7EvtDnra4EZRmBzi2gFAz0lbKg1+tMw== X-Received: by 10.194.175.106 with SMTP id bz10mr51732136wjc.42.1473325466464; Thu, 08 Sep 2016 02:04:26 -0700 (PDT) Received: from [192.168.0.98] ([93.188.182.58]) by smtp.gmail.com with ESMTPSA id 1sm2648633wmm.0.2016.09.08.02.04.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Sep 2016 02:04:25 -0700 (PDT) References: <232F1604-2211-4351-B830-EDC958A25D6D@strojny.net> <2de35db0-9974-cc96-83dd-3d2dbd48f7f8@lsces.co.uk> <5b72e9da-068a-bc79-82c2-f36f723f42bb@gmail.com> To: "internals@lists.php.net" Message-ID: Date: Thu, 8 Sep 2016 10:02:33 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC][VOTE] Add validation functions to filter module From: rowan.collins@gmail.com (Rowan Collins) On 08/09/2016 09:28, Yasuo Ohgaki wrote: > This might be the largest difference. > > To make something secure than it is now, adding additional security > layer is effective, not single location/code. My instinct is that this extra location would be a maintenance nightmare, as it would need to keep up with changes elsewhere in the application. In day to day use, what would make this extra security layer any more likely to be comprehensively maintained than the existing validation layer? > Suppose we have validation module. You are suggesting something like > > $int = validate_int($var, $min, $max); > $bool = validate_bool($var, $allowed_bool_types); > // i.e. which type of bool 1/0, yes/no, on/off, true/false is allowed > // This isn't implemented. All of them are valid bools currently. > $str = validate_string($var, $min_len, $max_len); > $str = validate_string_encoding($var, $encoding); > $str = validate_string_chars($var, $allowed_chars); > $str = validate_string_regex($var, $regex); > $str = validate_string_degit($var, $min_len, $max_len); > $str = validate_string_callback($var, $callback); No, I'm suggesting something like: if ( ! validate_int($var, $min, $max) || ! validate_bool($var, $allowed_bool_types) || ! validate_string($var, $min_len, $max_len) || ! validate_string_encoding($var, $encoding) || ! validate_string_chars($var, $allowed_chars) || ! validate_string_regex($var, $regex) || ! validate_string_degit($var, $min_len, $max_len) || ! $callback($var) // Note: no need to wrap this callback, it's just a boolean-returning function ) { // ERROR } It was a deliberately narrow purpose as an example, but IMHO that's perfectly readable, and the focus of the module would be on creating a good set of validation rules, rather than worrying about how they're applied. > [...] Rule reuse and centralizing validation rule is easy. The language provides us plenty of ways to reuse code. For instance: function validate_my_field($var) { return validate_int($var, $min, $max) && validate_bool($var, $allowed_bool_types) // etc } Regards, -- Rowan Collins [IMSoP]