Skip to content

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

Closed

Description

@chirag127

Problem

Phrase::generate() builds the anti-phishing security phrase shown in magic-URL / email-OTP flows using array_rand(), which is not cryptographically secure (PHP docs: "This function does not generate cryptographically secure values, and must not be used for cryptographic purposes.").

Cite

src/Appwrite/Auth/Phrase.php:13-14

$adjective = $adjectives[array_rand($adjectives)];
$noun = $nouns[array_rand($nouns)];

Consumed as anti-phishing phrase in app/controllers/api/account.php:2168 and :2494 (magic-URL / email-token flows).

Expected

Use random_int(0, count($x) - 1) (CSPRNG) so an attacker observing a few phrases cannot predict the next one to craft a matching phishing email.

Actual

array_rand() uses Mersenne Twister; state is recoverable from observed outputs.

Environment

composer.json requires php: >=8.3.0; branch main.

Thanks for maintaining appwrite/appwrite!

Activity

  1. added
    product / functions
    product / messaging
    on Jul 4, 2026
  2. Swaraj234 commented on Jul 4, 2026

    @Swaraj234

    Hi! I'd like to contribute this fix by replacing array_rand() with random_int() for the anti-phishing phrase generation. Could you please assign this issue to me? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    product / functionsproduct / messaging

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions