Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:95971 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 670 invoked from network); 13 Sep 2016 04:20:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Sep 2016 04:20:47 -0000 Authentication-Results: pb1.pair.com smtp.mail=oishi@giraffy.jp; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=kazuo@o-ishi.jp; sender-id=pass Received-SPF: pass (pb1.pair.com: domain giraffy.jp designates 49.212.134.110 as permitted sender) X-PHP-List-Original-Sender: oishi@giraffy.jp X-Host-Fingerprint: 49.212.134.110 www7096uf.sakura.ne.jp Received: from [49.212.134.110] ([49.212.134.110:53080] helo=xii.giraffy.jp) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C7/E6-60695-C9E77D75 for ; Tue, 13 Sep 2016 00:20:45 -0400 Received: from localhost (localhost [127.0.0.1]) by xii.giraffy.jp (Postfix) with ESMTP id 60F477A80B5; Tue, 13 Sep 2016 13:20:41 +0900 (JST) X-Virus-Scanned: amavisd-new at giraffy.jp Received: from xii.giraffy.jp ([127.0.0.1]) by localhost (xii.giraffy.jp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id MUHsXxkns3KL; Tue, 13 Sep 2016 13:20:37 +0900 (JST) Received: from lil.giraffy.jp (aa024044.ppp.asahi-net.or.jp [110.5.24.44]) by xii.giraffy.jp (Postfix) with ESMTPSA id 219807A80A0; Tue, 13 Sep 2016 13:20:37 +0900 (JST) To: Yasuo Ohgaki Cc: "internals\@lists.php.net" In-Reply-To: (Yasuo Ohgaki's message of "Tue, 13 Sep 2016 12:07:53 +0900") References: <878tuxenl4.fsf@lil.giraffy.jp> <87twdlcs2j.fsf@lil.giraffy.jp> <87h99lch13.fsf@lil.giraffy.jp> <877fagczci.fsf@lil.giraffy.jp> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Date: Tue, 13 Sep 2016 13:20:36 +0900 Message-ID: <87mvjcbfcb.fsf@lil.giraffy.jp> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [PHP-DEV] [RFC][DISCUSSION] Improve uniqid() uniqueness From: kazuo@o-ishi.jp (Kazuo Oishi) Hi, > Actually not with current implementation. If time is rewined, the same ID > could be generated by chance. Because, both ID part and entropy part > is generated based on the current system time. Collision would be rare, > but it's not rare as it should be at all. > > I think minimum would be 64 bits, 128 at least, 256 bits recommended. > > How about use 2nd parameter for entropy length? 0 for none, 1 for > default, 10 to 255 chars. > > Then user can have choice for prefered number of entropy chars. I think, uniqid should be left as is. >>> How serious BC is? >> >> You should already know that this BC-break breaks existing >> valid PHP codes in some situation. (DB error, test failure, etc.) >> >> BC-break may be acceptable if the change is clearly great improvement >> or obviously necessary. But this change is not, I think. > > I do think this is needed. > > Let's not please security audit companies. Use of current uniqid() in > security sensitive context is fatal because it is too easy to predict > generated ID even with "more_entropy". Letting make such mistake > moderate is worth the change. Misuse is just a misuse. The function uniqid() will not be a secure function to be able to use in security sensitive context even if this RFC is passed, isn't it? > In short, making PHP be more secure platform (tolerant even for > mistakes) matter to me. IMO, THIS change is not important enough and not effective enough to do in BC break way. > This BC is nothing compared to mt_rand() everywhere. It would be worth enough. (cryptographically secure random > predictive by seed) > Anyway, let's talk BC with real code. > > I didn't look into all, but only briefly. > https://searchcode.com/?q=uniqid&loc=0&loc2=10000&lan=24 Why didn't you... You said "BC (BC break) will be minimum"... > I could only find one code that tests uniqid() return value to test uniqid() (?) Example: https://github.com/BrianPrz/worklist/blob/master/classes/Login.class.php In this class, output of uniqid() is saved to DB (maybe). If 'token' field has only 13 length, output length change cause problem. > Other than that, almost all code does not care about uniqid() return > value at all. > Who cares about uniqid() return value? for what purpose? other than testing > uniqid() itself? The uniqid() manual explicitly say, - default value of more_entropy is false - the returned string will be 13 characters long. If more_entropy is TRUE, it will be 23 characters. - if more_entropy is set to TRUE, uniqid() will add additional entropy (using the combined linear congruential generator) at the end of the return value http://php.net/manual/en/function.uniqid.php So, it is fairly valid to design - field length limit to 13 chars in validation code or DB column. - acceptable character type limit to "[0-9A-Za-z]+". - expect increasing value in their PHP applications. -- Kazuo Oishi