You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[serverpod_auth] User ids should not be guessable #554
serverpod_auth generates consecutive user ids, starting from 1. User profile images are served at URLs that include the user id. Therefore, a hacker could exfiltrate all user profile images by simply iterating through user ids.
User ids should not be guessable. It would be much better to hash userIdentifier (the email address) using SHA256, and then use the first 8-ish bytes of this hash code, in some base, as the user ID.
This could be used for generating apparently-random 32-bit user ids from sequential integers when user accounts are created, in order to make user ids non-guessable.
You create the id column using something like
createsequenceseq maxvalue 2147483647;
createtabletablename(
id int default skip32(nextval('seq')::int, key, true),
[other columns]
);
It may also be worth considering an even wider hash function, since limiting to 2B user IDs could become a problem for some projects. Here's a different 64-byte function that could be used:
Would anyone object to me implementing this id order obfuscation method as the default for userId, as shown in the previous comment?
I'm guessing this should use 52 bits (and therefore needs to use bigint in Postgres), to fit into dart ints, while still having the requisite even number of bits.
Activity
yahu1031 commentedon Jan 10, 2023
@lukehutch Yes, The id in these tables is not preferred use for UUIDs. Please use uuid and create a column for UUID and use it. More ref #351
lukehutch commentedon Jan 10, 2023
There's actually a
hashcolumn already that could be used as the user ID (although it probably needs to be truncated a bit).yahu1031 commentedon Jan 10, 2023
Then perfect. IDK about it. Thanks for Letting me know. Please feel free to share more info if you have.
lukehutch commentedon Mar 21, 2023
I found a Postgres function that invertably maps the Uint32 space onto a permutation of the Uint32 space, based on a 32-byte key.
https://wiki.postgresql.org/wiki/Skip32_(crypt_32_bits)
This could be used for generating apparently-random 32-bit user ids from sequential integers when user accounts are created, in order to make user ids non-guessable.
You create the id column using something like
It may also be worth considering an even wider hash function, since limiting to 2B user IDs could become a problem for some projects. Here's a different 64-byte function that could be used:
https://stackoverflow.com/a/29962222/3950982
Dart has 53 bits of integer precision, so this could have to be modified to work with two halves of 26 bits of precision each.
lukehutch commentedon May 26, 2023
Would anyone object to me implementing this id order obfuscation method as the default for
userId, as shown in the previous comment?I'm guessing this should use 52 bits (and therefore needs to use
bigintin Postgres), to fit into dart ints, while still having the requisite even number of bits.SandPod commentedon Dec 17, 2024
This duplicate issue contains some perspectives to take into consideration for this: #646
marcelomendoncasoares commentedon Mar 28, 2026
Closing as completed since the new auth uses UUIDs for the users.