mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-24 14:50:17 +03:00
`src/utils/random.ts` was built on Math.random(), and it backs the token
generator, htpasswd salts and the passphrase suffixes. The PIN code
generator and the database builder's default password called Math.random()
directly. All now go through crypto.getRandomValues() with rejection
sampling, so indices are unbiased, for ranges up to 2^53.
The passphrase generator no longer calls generateSillyPassword(), which also
picks words with Math.random(). It uses the package's word lists with the
secure helpers, and skips pulling lodash and zxcvbn into the bundle.
Behaviour changes that came with it:
- randIntFromInterval() now includes its upper bound. The lorem ipsum
sliders could never reach their maximum and the passphrase generator never
put a number on the last word. The coin flipper used `0..10 % 2`, which
would be biased with an inclusive range, so it now draws 0 or 1.
- randIntFromInterval() orders reversed bounds, rounds fractional ones
inward and returns NaN for non-finite input instead of throwing.
- The lorem ipsum generator falls back to its defaults for malformed
`paragraphs`, `sentences` and `words` URL values and clamps them to the
slider ranges, so a link like `?sentences=[1,4294967297]` cannot freeze
the page.
- Passphrases whose length equals the min or max length are accepted.
- Multi-word list entries ("wide eyed") count as one word, so the word count
and number placement match the settings.
- Token generator draws each character independently instead of shuffling
the alphabet repeated `length` times.
Fixes the CodeQL js/insecure-randomness alert in the passphrase generator.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>