Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115016 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 43804 invoked from network); 22 Jun 2021 10:13:03 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 Jun 2021 10:13:03 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DF1E81804D0 for ; Tue, 22 Jun 2021 03:31:17 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 22 Jun 2021 03:31:17 -0700 (PDT) Received: by mail-pj1-f42.google.com with SMTP id x21-20020a17090aa395b029016e25313bfcso1995609pjp.2 for ; Tue, 22 Jun 2021 03:31:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=rmOrH6Fu+jKqnIQbPiEg5Wt/1fEi+GmXe6hW95rT9Cs=; b=m2v3TSY0Fo6lcESWQAxwRnRjMHbttkSn2Z6855a8D3V9uv3jW4WZuNIVm/5wm6zj3I r64bBnx4HCfcUyr4GThj/2906vWTcnI8U3IAwJIlLYERJytYxV7P8PATyqxCZyJiJ54w X6PUpR7uVPoeQ7sl5YyjIqipCQDZvOESSxnPTZMK/tuc3fAuQtnjdcvrq/UmL8qOIt9F /cy+PHUI5E+NuHtml7Ax8aCLu+yoFk1MbQZVQANNtU1saFU6YFzLIqjKncLPux0jD8AZ rv1HDMEW6yoGRiWFDZNCVlbRkJ1IXss1bx0MnsuTpSS2bnvXjqYrz9QGlUeBy8Ck43lo TFJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=rmOrH6Fu+jKqnIQbPiEg5Wt/1fEi+GmXe6hW95rT9Cs=; b=K4t1Q0BruTTwEKSAuSrS9xRCWF+mIZNVK8mbH6G5w8jwl9i+q8s2J6Iv0w3aDW3feA BS7mr0px7kDtT3RDPk6GHlrZ4fUZUULe3wqHZYKoIFGAzGT51MA/St3WFU69zfrFeI2l svUbhiwFU4w9aD+DYSqlyWKg+THXUUAYDWrLNCMk4S6efhWbQgvsJ+eDXadu/fA/X8AI f7LOKcsN9ViWEPaY22shNkp//LgrhHlf9pbj4/3YaSDZSSjFx/8tU7RvXFbx8QQVlhnV 4hAZ+zkkgg3HB0S8X6aJDRByNeoukxvTjgsEx4eDVQPJAhcc7IB/npkOIMAnrF0rvVBS dluw== X-Gm-Message-State: AOAM533eoCC31MWcO3p7r6BQ9rrgMCcJhuoy8ZIxItc8n2lNAedWq/UP pwYHGkpfjL2wrR2JZpGM9t2uN3iuBKfYzUlHlDxmvF5yJkDnqRrD X-Google-Smtp-Source: ABdhPJwfb/+XCNjKdlv10A8gz4ANBmGUAdS6VRMYmfUsTJgpmvnt2DLen4aX4oelbc7ebl1I0oAM1AXNhEizju2iKz0= X-Received: by 2002:a17:902:e04e:b029:10f:133f:87c8 with SMTP id x14-20020a170902e04eb029010f133f87c8mr22084767plx.70.1624357874673; Tue, 22 Jun 2021 03:31:14 -0700 (PDT) MIME-Version: 1.0 References: <7b1af9310312e0b1435b93490160e08d@gmail.com> In-Reply-To: <7b1af9310312e0b1435b93490160e08d@gmail.com> Date: Tue, 22 Jun 2021 12:30:38 +0200 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="0000000000001bb15e05c5584a8b" Subject: Re: [PHP-DEV] [RFC] is_trusted - was is_literal From: divinity76@gmail.com (Hans Henrik Bergan) --0000000000001bb15e05c5584a8b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable How is one supposed to use this? like if(!is_trusted($val)){ $val =3D htmlentities($str, ENT_QUOTES | ENT_HTML401 | ENT_SUBSTITUTE | ENT_DISALLOWED, 'UTF-8', true); } echo "
$val
"; (...) if(!is_trusted($val)){ $val =3D $mysqli->real_escape_string($val); } $mysqli->query("INSERT INTO tbl VALUES('$val');"); like that? (my first impression is that this sounds stupid, but i haven't given it enough thought to be sure) On Tue, 22 Jun 2021 at 11:48, Lauri Kentt=C3=A4 wr= ote: > On 2021-06-21 23:25, Craig Francis wrote: > > > > - Integers are now included, which will help adoption: > > > > https://wiki.php.net/rfc/is_literal > > > > Thanks for the great improvements! > > sprintf seems to have some issues, though. > > Currently you're checking the parameter types, not the formats. > The parameter type matters only when coercing to a string (%s). > Otherwise sprintf should consider the format, not the parameter. > > Example: > function test($s) { var_dump($s, is_trusted($s)); } > setlocale(LC_ALL, "de_DE.UTF-8"); > test(sprintf("SET c =3D %c, f =3D %f, e =3D %e", 0x27, 1234, 1234)); > test(sprintf("SET d =3D %d, x =3D %x, b =3D %b", 1e2, 1e2, 1e2)); > test(sprintf("SET weird_d =3D %''*d", 4, 1)); > test(sprintf("SET s =3D '%s', int to string should be ok", 123)); > ?> > > Currently: > string(43) "SET c =3D ', f =3D 1234,000000, e =3D 1.234000e+3" > bool(true) > string(32) "SET d =3D 100, x =3D 64, b =3D 1100100" > bool(false) > string(18) "SET weird_d =3D '''1" > bool(true) > string(41) "SET s =3D '123', int to string should be ok" > bool(true) > > Obviously the results with ints and floats should be the opposite. > > If you really want to allow %c, so be it, but I'd disallow it on the > grounds that (1) it's probably not used in secure strings (usage data, > anyone?), and thus (2) it could easily be a misspelled %d (for example, > '%c' instead of '%d' could silently produce an empty result in a query), > and (3) you're allowing a simple workaround with %s and chr() which > makes the intent more obvious. > > In general, as this is supposed to be a security feature, allowing > multiple ways for uninformed people to produce "trusted" but actually > very unsafe values doesn't look like a good idea. I'm not sure if > allowing trusted single characters to be created through chr or %c > serves any useful purpose, but I can imagine people using either one > without realizing that they can create any character, including \0 or ' > or " or non-UTF-8. Better to leave only chr(), one less thing to worry > about. > > Custom padding is a weird edge case, maybe just disallow that too? > > As you said yourself, it's not easy to prove anything safe. ;) > > -- > Lauri Kentt=C3=A4 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --0000000000001bb15e05c5584a8b--