Live data from Hacker News

Three mistakes from Dart/Flutter's weak PRNG

zellic.io

21–30 of 93 posts

Re: Three mistakes from Dart/Flutter's weak PRNG

#21
This 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.

Re: Three mistakes from Dart/Flutter's weak PRNG

#22
>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...

Re: Three mistakes from Dart/Flutter's weak PRNG

#23
post #10

New 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.

Rust does this.

IMO, it's not worth it: It makes working with random numbers very problematic when working on cryptographic use cases.

Re: Three mistakes from Dart/Flutter's weak PRNG

#25
For 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).

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.

Re: Three mistakes from Dart/Flutter's weak PRNG

#26
post #10

New 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.

Arguably, rolling your own crypto (in this case AES which is customizable) requires a very careful implementation, beyond RNG.

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

Re: Three mistakes from Dart/Flutter's weak PRNG

#27

I’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

No, 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.

Re: Three mistakes from Dart/Flutter's weak PRNG

#28
post #23
post #10

New 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.

Rust does this. IMO, it's not worth it: It makes working with random numbers very problematic when working on cryptographic use cases.

Could you clarify this? What problems would you run into just from having the default RNG be secure?

Re: Three mistakes from Dart/Flutter's weak PRNG

#29
post #21

This 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.

With 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.

Post reply on HN