sveltejs / cli

The Svelte CLI
MIT License
259 stars 11 forks source link

Lucia adder: Reduced entropy in IDs when using MySQL #261

Closed pilcrowonpaper closed 2 weeks ago

pilcrowonpaper commented 2 weeks ago

In the Lucia adder, both the session and user IDs are case sensitive since they're base64-encoded (a-z, A-Z, 0-9). However, by default, string comparisons are case insensitive in MySQL so the character set is reduced 38 characters. This reduces the entropy of the user ID from 120 bits to \~106 bits, ~and more importantly, the session ID from 144 bits to \~127 bits. This is fortunately still higher than the 112 bits recommend by the NIST but should be fixed.~ Fix: This doesn't affect session tokens since we hash them and hex encode it before storage.

So we have a few options here:

  1. Use the BINARY column type for IDs: This can make debugging harder since values won't be human-friendly when viewing data.
  2. Set the ID column collation to utf8mb4_bin: Not supported by Drizzle https://github.com/drizzle-team/drizzle-orm/issues/638.
  3. Use the BINARY operator when running SELECT: Also not supported by Drizzle and error prone.
  4. Use base32 instead of base64, which is case insensitive (uses a-z, 2-9)

I think (4) is the easiest and we should probably add a warning on using case sensitive IDs.

Also kinda relevant #163