10 ms·
Three mistakes from Dart/Flutter's weak PRNG
- bsimpson 2y ago[flagged]
- sksrbWgbfK 2y agoI expect readers of HN to know the acronym PRNG, and that random must be seeded all the time and must NOT be used for secure things. But we're living in the age of LLMs that create perfect code while programmers know nothing anymore.
- lann 2y agoThis comment really assumes you know the acronym LLM
- high_priest 2y agoAre PRNG the letters on an automatic transmission stick?
- busterarm 2y agoOr that you have a web browser with search capabilities that you're likely to use before complaining about acronyms... The term is table stakes for the audience this is written for.
- firefax 2y ago>The article really assumes you know the acronym PNRG Why would you be reading this article if you do not? This is the type of critique given when writing for a general audience, not a scientific whitepaper. (Fun fact: The AP style guide tells folks to write at an 8th grade level because that's reading level of the average American adult. 8th graders do not read white papers on cryptographic design, and when they do, they look up unknown acronyms just like big boys and girls do.)
- amake 2y ago> PNRG You sure about that?
- deleted 2y ago[deleted]
- robin_reala 2y agoI’m not a Dart fan so maybe I’m biased, but wow this (from the article) is a failure on many levels: https://github.com/dart-lang/sdk/issues/56609 https://github.com/dart-lang/sdk/issues/56609
- nickcw 2y agoFrom the code in the issue // TODO: Make this actually random static int _initialSeed() => 0xCAFEBABEDEADBEEF; Oops.
- orr94 2y agoThat TODO was committed on 2022-02-16 and wasn't fixed until 2024-09-2. That is... a long time for something that critical.
- abenga 2y agoOops indeed. I like using FIXME for such to make it stand out it's a deficiency that should be fixed asap (usually before merging the change altogether) compared to TODOs that are improvements that can be implemented in a more leisurely fashion.
- deleted 2y ago[deleted]
- swatcoder 2y agoNo, it's totally overblown. As discussed in the comments on that issue as an example, the failure was in whoever wrote Flutter's `uuid` feature. It's simply incorrect for them to have naively used a PRNG there, regardless of whether it has a static seed or not. They should have used Random.secure all along, and anyone working in a cryptographically sensitive module, like `uuid` should be familiar enough with the distinction to make the right choice. There's nothing especially harmful about having that static seed and there are even some diagnostic and debugging advantages offered by it. Shuffling the seed on init is a generous convenience for people who want to make sure there's more per-run variety in their randomness without setting a seed themselves, but (when using in a non-secure context) it quickly doesn't matter since anything but toy programs tend to have enough complexity, branching, and data-dependency that the sequence of invocations isn't consistent anyway.
- klooney 2y agoNew languages should make sure the default random() is cryptographically secure, and hide PRNGs behind weakrandom() or repeatablerandom() or something. Safe and slow defaults are better than fast and unsafe.
- tobyjsullivan 2y agosane defaults is always the goal. The only problem is people can't seem to agree on what behaviour is "sane".
- mjw1007 2y agoSo don't have a default. Have securerandom() and insecurerandom() and make the programmer choose. That has the advantage of avoiding problems in a generation's time: if most platforms moved to random() being secure, it would be excusable if young programmers started assuming that would be the case on older platform too.
- gwbas1c 2y agoRust does this. IMO, it's not worth it: It makes working with random numbers very problematic when working on cryptographic use cases.
- ivanbakel 2y ago
- goodburb 2y agoWhy did Proton and SelfPrivacy use Random instead of Random.secure? DTD is local host or over SSH due to the unecrypted websocket. Browsers block unsecure WS over HTTPS. The key generated is for tagging multiple instances per IDE not security. Random is instant and is used for runtime collision prevention and performance especially UI, not uniqueness, PRNG is not truly random anyways. Random.secure has a large overhead accessing OS entropy and isn't always supported. [1] Go 'math/rand', python 'Random', C# 'Random' to name a few are also not unique or safe for crypto. Their secure equivalents: Go 'crypto/rand', Python 'SystemRandom', C# 'RNGCryptoServiceProvider'. This isn't a Dart or Flutter issue [0]: "A generator of random bool, int, or double values. The default implementation supplies a stream of pseudo-random bits that are not suitable for cryptographic purposes. Use the Random.secure constructor for cryptographic purposes." [0] https://api.dart.dev/dart-math/Random-class.html https://api.dart.dev/dart-math/Random-class.html [1] https://api.dart.dev/dart-math/Random/Random.secure.html https://api.dart.dev/dart-math/Random/Random.secure.html
- swatcoder 2y agoYeah, it's a weird critique. The author acknowledges early on that `Random.secure` is there to provide randomness where it needs to be secure, but then spends the entire article fretting over how the other source of randomness isn't. But it's not supposed to be! Applications have plenty of reason for cheap, stable, or otherwise controlled forms of randomness and shouldn't have to pay the penalty for -- or face the reproducibility limitations of -- secure randonmness when that's not what they need. It's both useful and traditional for standard libraries to either include both forms, or to leave the secure form for other libraries to contribute. If an application uses the wrong supply of randomness for their needs, that's an application error. And if developers writing security-sensitive code don't know to think anticipate this distinction and avoid the error, then that sounds like there was a project management error in assigning them such a sensitive task.
- ivanbakel 2y agoWell the article still has a point in that the insecure PRNG is neutered for seemingly no reason, contrary to developer expectations. But I think we should, as language developers and users, be well beyond the point of pushing out and accepting insecure defaults with a little documentation disclaimer - especially if even the Dart developers themselves can't catch misuse of their own insecure APIs in widespread tools. At the end of the day, we don't live in a computing world where true randomness is that resource-intensive anymore, and user-facing applications should basically always be relying on it. Non-randomness should really be the opt-in, when developers can actually justify that the performance penalty is a problem. Otherwise, I don't need library authors prematurely optimising my programs at the cost of security. (There is a similar related discussion to have about the pervasiveness of floating points in programming languages when most applications would be better served by a more expensive, but more precise, numerical representation - since they rarely do that much calculation.)
- rumori 2y agoPRNG = pseudo-random number generator. I think it would have made sense to spell it out in the first sentence and go with the acronym from then on. Like the author does it with multiply-with-carry (MWC). Makes it more readable and consistent throughout the article.
- deleted 2y ago[deleted]
- tptacek 2y agoThis is weird, since it reads as a critique of the insecure random number generator in a language that has a secure random number generator. What does it mean for the insecure random number generator to be insecure? That's the point: it's the one you use when security doesn't matter, because you need speed or determinism.
- matthewdgreen 2y agoWith any question like this, the path to an answer follows three intermediate questions: 1. Was there a security problem that resulted from the use of this insecure generator? 2. Were the developers who encountered this problem completely unreasonable and in the wrong, or were they simply non-(security)-experts who developed software that happened to have a security vulnerability? 3. If the latter, did the language/toolkit strongly encourage developers to use an insecure generator -- e.g., by making an insecure generator the default or "simpler" option (such as Random() instead of Random.secure()). 4. Is there some broad and general understanding that this toolkit is only intended for applications, such as monte-carlo testing or graphics rendering, where performance at the cost of security will always be the correct solution? Given that the authors are able to offer several examples of real security vulnerabilities caused by developers using an insecure PRG, I'm going to read the answers as (1) Yes, (2) not unreasonable, (3) Yes, (4) I don't think so. The decision to make insecure RNGs the default creates security vulnerabilities. This is demonstrable and has broad and unpredictable effects, given that developers are not security experts. The decision to make secure RNGs the default (easier path) has exactly one implication, which is that a small number of specialized applications will have slightly worse performance, performance that can easily be improved by making a conscious decision to remove the secure RNG.
- tedunangst 2y agoWait. Developers consciously chose to use this random because they believed it had a 64 bit seed? That's still wrong. It's irrelevant that it was truncated to only 32 bits.
- tptacek 2y agoThat may be, but having the default generator be non-cryptographic has been the conventional design choice in languages since the dawn of time. I would get the willies seeing security-sensitive code using "Random()" even if you told me in your language "Random()" was a CSPRNG.
- 999900000999 2y ago>November 1, 2024 — The Google Bug Hunters team decided to not reward nor announce this security fix, because it only affects developers. Good to know Google doesn't care about my security. Long time Flutter user, but Google expresses disdain for it at every opportunity... Might see if the C# mobile frameworks have caught up...
- mightyham 2y ago[flagged]
- deleted 2y ago[deleted]
- BoorishBears 2y agoThe title had me quietly think to myself "Dart was the mistake". So many stack/enviornments are leveling up their languages: ObjC => Swift, Java => Kotlin, Erlang => Elixr, C++ => Rust, Javascript => Typescript Dart feels like one of the befores, not the afters.
- throwaway032023 2y agoFeels is the key to that statement. :-) It’s these “feels” that got USA to its 2024 election outcome.
- BoorishBears 2y agoAre you ok?
- throwaway032023 2y ago> It's clear just from using the language that it was designed as a more "serious" Javascript replacement What is your usage of Dart? JavaScript is a target platform for Dart. The Dart interop story is the point. It’s a cohesive glue language. First class interop with JavaScript, Java/Kotlin, C++ and Swift/ObjC. Community interop supports go and rust. Maybe I am confused. We are comparing Dart to what again? Yes, Flutter is what Dart is known for and it’s, imho, important for their to be primary customer to drive evolution of language. I don’t do JavaScript development but anytime I bump into it it’s a cluster with regards to tooling (maybe this has changed in the past 3 years). Dart comes ootb with tooling that is a cohesive experience. The technology is impressive and I think it’s filling a niche. Dart reminds me of Python 20 years ago. Python shipped with IDLE, glued platform (win32com), corba, java, etc features together. Dart is doing similar stuff but first class interop from the supplier (Google/dart team) for the platforms (js/wasm, mobile, desktop). It is pretty damn amazing and ambitious (maybe too ambitious?). And pub/package system is nice - dart is statically compiled and Google is one of the main innovators in software supply chain security - I think there is real possibility of it being orders of magnitude more secure than python/javascript. (This is not the case currently) I guess I see it as a “I can stay in this world and do most of what I need”. Are there sharp edges? Yes. But the tooling and the community can resolve this fairly quickly. I don’t need to jump between abuncha languages with tooling disparaties.
- keepamovin 2y agoFor a PRNG you should probably be using something like a good hash function that passes the SMHasher3 tests to generate it (which funnily enough I just posted now after a long overdue enhancement: https://news.ycombinator.com/item?id=42409577 https://news.ycombinator.com/item?id=42409577). Alternately develop something that at least passes all the Dieharder tests. There are many good options for a variety of requirements. Maybe the following perspective is missing some key context here (?) but when I skimmed the code for this, I was stunned that such a low quality algorithm was used by Zellic (some kind of high end cyber genius cabal, it seems) and in cryptocurrency purposes. I'm rarely harsh on projects here but bloody hell that's utterly stupid. Especially when there are so many good options.
- dgrove 2y agoThis feels like MilkSad.info and the 2020/2021 Cake Wallet flaws all over again https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-39910 https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-3991... https://milksad.info/posts/research-update-10/ https://milksad.info/posts/research-update-10/
- cmovq 2y agoPRNGs are insecure by design, why does this article frame the problem as the implementation being insecure? Applications shouldn’t use PRNGs if they need a true random source to begin with.
- colmmacc 2y agoThe only true random sources in the universe are quantum. But it's not practical or performant to hook your workload up to a raw quantum measurement like the spin of a fundamental particle, or radioactive decay. Instead we take sources that are still believed to be statistically random and influenced by underlying quantum randomness. E.g. RF interference, clock phasing, or an avalanche amplifier that are measures of entropy that is considered to be random to the same extent as say the ideal gas laws. But even those measures can still be imperfect; a probe might have a bias or manufacturing error that shows up later than QC. To cope with this, we have PRNG designs that can use mixed sources in ways that will provably debias any such errors from a single source, and remain secure. All modern RNGs use these kind of PRNGs or DRBG/NRBG designs as a last stage. Far from being insecure, they are what give us more confidence in the overall system.
- fermuch 2y ago> The only true random sources in the universe are quantum. But it's not practical or performant to hook your workload up to a raw quantum measurement like the spin of a fundamental particle, or radioactive decay. I was under the impression that's how entropy generators for servers work?
- deleted 2y ago[deleted]
- r2vcap 2y agoSome missing timelines: December 11, 2024 - Dart SDK 3.6.0 has been released. December 12, 2024 - Flutter SDK 3.27.0 have been released.