Skip to content

[serverpod_auth] User ids should not be guessable #554

Closed

Description

@lukehutch

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.

Activity

  1. yahu1031 commented on Jan 10, 2023

    @yahu1031
    Contributor

    @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

  2. lukehutch commented on Jan 10, 2023

    @lukehutch
    ContributorAuthor

    There's actually a hash column already that could be used as the user ID (although it probably needs to be truncated a bit).

  3. yahu1031 commented on Jan 10, 2023

    @yahu1031
    Contributor

    Then perfect. IDK about it. Thanks for Letting me know. Please feel free to share more info if you have.

  4. added
    enhancement
    on Jan 10, 2023
  5. lukehutch commented on Mar 21, 2023

    @lukehutch
    ContributorAuthor

    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

    create sequence seq maxvalue 2147483647;
    
    create table tablename(
     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:

    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.

  6. lukehutch commented on May 26, 2023

    @lukehutch
    ContributorAuthor

    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.

  7. added
    area: authentication
    on Dec 17, 2024
  8. SandPod commented on Dec 17, 2024

    @SandPod
    Contributor

    This duplicate issue contains some perspectives to take into consideration for this: #646

  9. marcelomendoncasoares commented on Mar 28, 2026

    @marcelomendoncasoares
    Collaborator

    Closing as completed since the new auth uses UUIDs for the users.

  10. moved this from Backlog 🗂️ to Done 🚀 in Serverpod Frameworkson Mar 28, 2026
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

    area: authenticationenhancement

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions