Skip to content

fix(auth): generate the anti-phishing phrase with a CSPRNG - #13943

Merged
HarshMN2345 merged 2 commits into
mainfrom
fix/issue-12783
Sep 28, 2026
Merged

HarshMN2345 merged 2 commits into
mainfrom
fix/issue-12783

Conversation

@HarshMN2345

Copy link
Copy Markdown
Member

What does this PR do?

Phrase::generate() picked both of its words with array_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 use random_int() over the zero-indexed word lists.

This is the pattern the sibling proofs already use: packages/auth/src/Proofs/Code.php draws each digit with random_int(0, 9), and Password.php indexes its charset with random_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 analyse on the file → [OK] No errors
  • vendor/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 to packages/auth as Utopia\Auth\Proofs\Phrase, which is in-repo source, so this needs no upstream release.

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs? — no metadata change

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.
@ghost

ghost commented Sep 28, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The PR replaces array_rand() with random_int() for both anti-phishing phrase words. It also brings the queue library into the repository as a Composer-autoloaded package, with package tooling and documentation, and adds the Redis claim script.

Latest changes: The newest commits absorb the queue library into packages/queue, wire its root autoloading and package metadata, add package documentation/tooling, and introduce the Redis claim Lua script.

Verdict New comments Fixed Still open
💬 Commented 0 0 0

Note

Part of the diff was too large to review, so Hansi did not approve.

📂 Walkthrough · 3
File Change
packages/auth/src/Proofs/Phrase.php Selects each phrase word using a cryptographically secure random index.
composer.json, bin/monorepo Autoloads and replaces the queue package locally, and allows package E2E Docker fixtures.
packages/queue/** Adds the queue package source, Redis Lua scripts, package configuration, tests, documentation, and mirror workflow.

Reviewed the commits since 702b33b · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@greptile-apps

greptile-apps Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Critical risk] Fixes cryptographic randomness in anti-phishing phrase generation.

The PR appears safe to merge.

Summary

This PR replaces array_rand() with random_int() for both words in the anti-phishing phrase, while preserving its output format.

Reviews (2) · Last reviewed commit: "Merge branch 'main' into fix/issue-12783"

@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/issue-12783 (after).

Metric Before After Change
🚀 Requests/sec 180.77 181.41 ⚪ +0.4%
⏱️ Latency P50 95.54 ms 94.82 ms ⚪ -0.8%
⏱️ Latency P95 228.99 ms 223.86 ms ⚪ -2.2%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 94.82 223.86 11,400 181.41 -5.12
Account 187.45 336.05 600 10.24 -14.93
TablesDB 91.39 173.75 6,200 101.15 -6.43
Storage 88.61 186.6 3,000 50.42 -5.8
Functions 138.43 272.71 1,600 27.56 +7.3

Top API waits (after)

API request Max wait (ms)
tablesdb.rows.get 620.67
tablesdb.rows.increment 550.32
tablesdb.rows.update 547.65
account.prefs.update 469.12
account.name.update 458.81

@HarshMN2345
HarshMN2345 merged commit 113c1d0 into main Sep 28, 2026
50 of 51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security phrase generator uses non-CSPRNG (array_rand) in Phrase::generate()

1 participant