Repository navigation
fix(auth): generate the anti-phishing phrase with a CSPRNG - #13943
Conversation
array_rand() draws from the Mt19937 generator, so a phrase was predictable from earlier ones. Index both word lists with random_int() instead, matching Code and Password.
🟢 Tier S · Ready to mergeThe PR replaces Latest changes: The newest commits absorb the queue library into
Note Part of the diff was too large to review, so Hansi did not approve. 📂 Walkthrough · 3
Reviewed the commits since |
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
What does this PR do?
Phrase::generate()picked both of its words witharray_rand(), which draws from PHP's Mt19937 generator. That is not a CSPRNG, so an anti-phishing phrase is predictable from earlier observed output. Both draws now userandom_int()over the zero-indexed word lists.This is the pattern the sibling proofs already use:
packages/auth/src/Proofs/Code.phpdraws each digit withrandom_int(0, 9), andPassword.phpindexes its charset withrandom_int(0, $max).The phrase is a display-only anti-phishing hint, so predicting it does not break an auth check — it makes a spoofed email more convincing.
Test Plan
composer lint packages/auth/src/Proofs/Phrase.php→{"tool":"pint","result":"passed"}vendor/bin/phpstan analyseon the file →[OK] No errorsvendor/bin/phpunit packages/auth/tests/Proofs/PhraseTest.php→ OK (3 tests, 7 assertions), run and watched. The existing suite already asserts the output shape, and the behaviour contract is unchanged, so no new test was added.Related PRs and Issues
The issue cites
src/Appwrite/Auth/Phrase.php, which no longer exists — the class moved topackages/authasUtopia\Auth\Proofs\Phrase, which is in-repo source, so this needs no upstream release.Checklist