96 points · by gnabgib · 1y ago · 84 comments
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 [1] https://api.dart.dev/dart-math/Random/Random.secure.html
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.
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.)
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.
On #2: The difference between a PRNG and a cryptographically secure random number generator is foundational knowledge for software engineers, and there's (finally) a strong trade consensus that writing security-sensitive code has a higher bar of preparation and shouldn't be done naively. It's entirely unreasonable that someone writing a `uuid` implementation that's meant to be a cryptographically secure library for use by application developers wouldn't anticipate that their standard library would offer both and would prioritize the PRNG as its basic and most accessible generator.
On #4: It's very rare that an application developer needs direct access to a cryptographically secure random number generator, especially because of that trade consensus that security-sensitive applications deserve expert care. In contrast, application developers are building test data pools, shuffling arrays, adding noise to signals, adding surprise to gameplay, writing and running reproducible tests, etc every day and naive use of a cryptographically secure random number generator in those contexts is easily paralyzing and catastrophic. The overhead can be order of magnitude in measure (which matters quite a lot in typical highly-repetitive/looped usage), and in some implementations it can introduce non-deterministic and potentially indefinite blocks on execution. And because they specifically can't be made deterministic by design, they significantly frustrate debug and test efforts that benefit from reproducibility. They're an essential tool in modern standard libraries, when they're needed in unusual cases, but are not suitable for naive everyday use at all.
* Most software developers (let's say, 95-99%+) are smart enough to avoid using insecure PRGs in their code.
* The remaining 1-5% have contributed to a litany of avoidable security disasters, nonetheless.
* The impact of these disasters has been vastly outsized when you compare it to the number of bad developers.
* If every developer understood that they needed security expertise (and indeed, that they were even writing security critical code, the world would be a very different place than it is.)
As Thomas mentioned below, I am something of a collector and obsessive when it comes to incidents of bad random number generation. What's fascinating to me about this Dart/Flutter story is not the result, it's that I haven't seen one of these stories in a long time!
By this I mean: this type of incident used to pop up on HN every month or so, and yet in the past few years they've become incredibly rare. And do you know why that is? It is not because developers got better. It's almost entirely due to the fact that development frameworks (particularly JS in browsers) have made a multi-year and systematic effort to reduce the availability of insecure default PRGs to bad developers. The result is that an entire bug class has gone from a common, monthly occurrence, to a relative rarity.
The idea that we should use insecure default RNGs because they're good for reproducible testing is a new one on me. If you need reproducible random numbers for your application, but you are asking to use an interface that does not explicitly include the fact that it generates non-random, reproducible numbers then you are doing both software development and testing wrong, IMHO.
Since dart/flutter is multi platform, using Random.secure for animation has it's own performance issues with interfacing host entropy RNG.
The majority of Dart/Flutter users are creating UI apps.
Few browsers with security policies and OS combination does not allow access to the entropy with Flutter Web in which Random.secure will fail, this isn't exclusive to Dart/Flutter. [1]
NaCL [0] offloads these concerns for developers, especially indie/startup.
[0] https://en.wikipedia.org/wiki/NaCl_(software)
[1] https://api.dart.dev/dart-math/Random/Random.secure.html
I'm more a fan of "make the defaults as secure as you can reasonably expect to get away with for each step of the way". It'll never be as secure as everyone wants but if you but up against "it's as secure as people would want to put up with by default" then things are at least at a good starting point for others to build from. The hard part is finding out what people are willing to put up with and which tradeoffs are worth it. That default random number generators "only" go at GB/s on most PCs because they produce really good random numbers is probably an easy tradeoff though.
- randomWeak() - randomSecure()
[0] In my experience, most of them -- who reads documentation these days...? Or programmers using editors like vim (no slight on vim by the way, don't shoot me!) which (generally) won't alert the programmer to the library options, unless it's been set up with a suggestion/completion/intellisense plugin?
[1] randomSecure() vs randomInsecure(), which can look similar at 3:00am on three hours sleep. Naming the functions explicitly differently makes it patently clear which function is cryptographically safe. Also helps when the interpreter/compiler won't understand the context the function is being called in, therefore can't throw warnings or errors to alert the overtired/overworked programmer that they're using insecure random number generation for crypto.
Big brain idea: Perhaps cryptographically-weak/insecure random number generators should be type incompatible by default, requiring an explicit cast to integer/float? Probably overkill, but definitely wards off mistakes and/or misuses by forcing the developer to type cast out, otherwise the compiler simply refuses, then explains why by fatal error at compile time, or by exception thrown.
But then why not make secure random number generators type incompatible by default? Because we're trying to encourage secure-by-default programming, making it slightly harder (but not onerous) to use the equivalent insecure function over secure one. Create a speed bump to prompt the programmer to think about their code, not a road block.
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.
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.
I was under the impression that's how entropy generators for servers work?
https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-3991...
December 11, 2024 - Dart SDK 3.6.0 has been released. December 12, 2024 - Flutter SDK 3.27.0 have been released.
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.
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.
// TODO: Make this actually random
static int _initialSeed() => 0xCAFEBABEDEADBEEF;
Oops.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...