upvote
It's such a simple mistake that you and LLM review can miss if not specifically looking for it, especially if it's in a dependency. Lots of folks don't know that Math.random() is insecure and they should be using Crypto.getRandomValue(), it's mostly bad language design, from an age where security was just an afterthought even more so than today. For LLMs it's trivial to find such instances.

That said any good security audit would have turned this up well before the age of LLMs, we were checking for weak RNG values first thing when looking at a new codebase as it was often an easy finding along with e.g. weak hashing algorithms like MD5 or SHA1. I believe a lot of static analysis code scanning tools have rules that flag Math.random() as insecure as well.

reply
I don’t think any LLM would miss the use of Math.random where a cryptographic random should be used. Then again, I don’t think I know any programmers that would miss it. It’s not some advanced concept. It’s security 101 stuff.
reply
I had code using math.random() to generate passwords introduced into my codebase, written by opus 4.6 in Febuary 2026, and not found until November 2026
reply
Lots of old examples of code using Math.random() in the training data, probably more than Crypto.getRandomValue, given that Math.random has been around a lot longer.

You can try and train it out afterwards but there’ll always be a part of the model that wants to write everything with Math.random because so many people did in the past

reply
Sounds like if you’re building a security critical part (login) of a security critical server this should not be “easy to miss”. It should be the bread and butter of the person doing it.
reply
It should be, but rarely is.
reply
Opus 5.5 has specifically not used Math.random() on Typescript projects I've done.
reply
Let's not forget that crypto.getrandomvalue requires https which can force developers not using local https to use the insecure methods which they inevitably forget to update before shipping, all in the name of security by our great browser overloards and their infinite wisdom.
reply
"http://localhost:*" and "http://\*.localhost:\*" are considered a secure origin, so you don't need HTTPS for it.
reply
I think it was true that you needed local https at one point (I vaguely remember setting it up once) but yes it no longer is
reply
They are using nodejs, not a browser to handle server side POST requests.
reply
BTW, a way to fix it is to create your own "localhost" name and issue a certificate for it. Then just commit it into your code repository.

I used to do that once every 3 years with a "regular" SSL provider. Unfortunately, now the longest period is 200 days. I'll have to set up Let's Encrypt automation for it eventually :(

reply
I mean depending on what you're doing you should be able to set up your own local CA and put the root cert on your internal devices and get certs as long as you want.
reply
Local CAs are a pain in the ass to maintain, and they are a huge vulnerability. If your CA private keys leak, your devices can be MITM-ed.

It pops up in all kinds of places, like CI/CD runs or automated tests.

reply
Hence you build your certs on an offline laptop.
reply
[dead]
reply
Hey! So do I but you needed the paid version to get enough attempts to get enough data iirc
reply