[Security] ID generation should generate UUIDs, not just some random strings #1595

Closed
opened 2026-03-13 08:50:28 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @KazimirPodolski on GitHub (Jul 28, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Use e.g. sign-up with email.

Current vs. Expected behavior

Generated record has an ID like v6c7zOwP9oBMDg3QpRdVJPhphrkOVrgu instead of a proper UUID. No proof of cryptographic and collision hardness of better-auth's own generator is to be found.

What version of Better Auth are you using?

1.3.4

Provide environment information

Doesn't matter.

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

This states:

Battle-tested auth flows and security practices

Except rolling your own random generator is literally one of the oldest mistakes in the book.

Please use Node's randomUUID or something.

Guys @Bekacru @Kinfe123 @ping-maxwell, this is more serious than you think. Apart from purely technical mistake, it also breaks trust in the platform, as other security-related malpractices could be expected randomly.

Originally created by @KazimirPodolski on GitHub (Jul 28, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Use e.g. sign-up with email. ### Current vs. Expected behavior Generated record has an ID like `v6c7zOwP9oBMDg3QpRdVJPhphrkOVrgu` instead of a proper UUID. No proof of cryptographic and collision hardness of [better-auth's own generator](https://github.com/better-auth/utils/blob/67e06576b8504331fcc9cf51479719ce4fc6db24/src/random.ts#L20-L69) is to be found. ### What version of Better Auth are you using? 1.3.4 ### Provide environment information Doesn't matter. ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context [This](https://www.better-auth.com/docs/comparison) states: > Battle-tested auth flows and security practices Except rolling your own random generator is literally one of the oldest mistakes in the book. Please use Node's `randomUUID` or something. **Guys @Bekacru @Kinfe123 @ping-maxwell, this is more serious than you think.** Apart from purely technical mistake, it also breaks trust in the platform, as other security-related malpractices could be expected randomly.
GiteaMirror added the security label 2026-03-13 08:50:28 -05:00
Author
Owner

@KazimirPodolski commented on GitHub (Jul 28, 2025):

I understand there is the ability to override ID generation, but default behavior should not be wrong anyway.

@KazimirPodolski commented on GitHub (Jul 28, 2025): I understand there is the ability to override ID generation, but default behavior should not be wrong anyway.
Author
Owner

@Bekacru commented on GitHub (Jul 28, 2025):

Thanks for the feedback

First off, we're not "rolling our own crypto", we use getRandomValues under the hood, which is cryptographically secure and available in both browser and Node environments and used by randomUUID itself.

Second, I think the term you're looking for is collision probability, not collision hardness (typically refers to hash functions). In this case, it's more about the probability of generating the same random value twice and depending on how you configure our generator, it can actually offer higher entropy than UUIDv4 for the same length.

You're right that UUID is a well-established standard and it's a good suggestion. But we intentionally chose a more agnostic approach. Users can use UUID, CUID, NanoID or just their db generated ID if they see fit, we don’t want force a specific format.

@Bekacru commented on GitHub (Jul 28, 2025): Thanks for the feedback First off, we're not "rolling our own crypto", we use `getRandomValues` under the hood, which is cryptographically secure and available in both browser and Node environments and used by randomUUID itself. Second, I think the term you're looking for is collision probability, not collision hardness (typically refers to hash functions). In this case, it's more about the probability of generating the same random value twice and depending on how you configure our generator, it can actually offer higher entropy than UUIDv4 for the same length. You're right that UUID is a well-established standard and it's a good suggestion. But we intentionally chose a more agnostic approach. Users can use UUID, CUID, NanoID or just their db generated ID if they see fit, we don’t want force a specific format.
Author
Owner

@ahmafi commented on GitHub (Jul 31, 2025):

Another thing that comes to mind is that a random value is not really good for indexing, something like a uuidv7 would be probably better. Maybe when it's available in more providers, it can be the default value. Postgres 18 added uuidv7 recently.

@ahmafi commented on GitHub (Jul 31, 2025): Another thing that comes to mind is that a random value is not really good for indexing, something like a `uuidv7` would be probably better. Maybe when it's available in more providers, it can be the default value. Postgres 18 added `uuidv7` recently.
Author
Owner

@KazimirPodolski commented on GitHub (Jul 31, 2025):

In this case, it's more about the probability of generating the same random value twice and depending on how you configure our generator, it can actually offer higher entropy than UUIDv4 for the same length.

Sorry but that's just not how it works. You'll need to prove that and if you try, you'll find it much much harder that just a line of thought. But I'm not ready to argue that far, please feel free to close the issue if you won't have an action.

@KazimirPodolski commented on GitHub (Jul 31, 2025): > In this case, it's more about the probability of generating the same random value twice and depending on how you configure our generator, it can actually offer higher entropy than UUIDv4 for the same length. Sorry but that's just not how it works. You'll need to prove that and if you try, you'll find it much much harder that just a line of thought. But I'm not ready to argue that far, please feel free to close the issue if you won't have an action.
Author
Owner

@kevlened commented on GitHub (Jul 31, 2025):

@KazimirPodolski It’s trivial to show a higher entropy for the same string length, because the character set of uuid is case-insensitive [A-Z0-9], whereas the character set of the custom id is [A-Za-z0-9]. This doesn’t include the extra hyphens in uuid.

As for the randomness, the utility uses a very common secure sampling method. Additionally, there are tests in the utility library to test for bias: 67e06576b8/src/random.test.ts (L145)

If you’re unhappy, you’re free to generate your own ids, but it’s alarmist to categorize this as a critical security issue.

@kevlened commented on GitHub (Jul 31, 2025): @KazimirPodolski It’s trivial to show a higher entropy for the same string length, because the character set of uuid is case-insensitive [A-Z0-9], whereas the character set of the custom id is [A-Za-z0-9]. This doesn’t include the extra hyphens in uuid. As for the randomness, the utility uses a very common secure sampling method. Additionally, there _are_ tests in the utility library to test for bias: https://github.com/better-auth/utils/blob/67e06576b8504331fcc9cf51479719ce4fc6db24/src/random.test.ts#L145 If you’re unhappy, you’re free to generate your own ids, but it’s alarmist to categorize this as a critical security issue.
Author
Owner

@amlcx commented on GitHub (Aug 16, 2025):

Although this is already closed, I think @ahmafi 's comment is worth considering. I understand the motivation for a random string unique ID, but having an UUID (especially version 7) would improve several areas; one of them: sorting and cursor-based pagination, which is arguably more efficient than offset-based pagination. Nonetheless, since rolling our own IDs is always an option, creating a new issue might be unnecessary.

@amlcx commented on GitHub (Aug 16, 2025): Although this is already closed, I think @ahmafi 's comment is worth considering. I understand the motivation for a random string unique ID, but having an UUID (especially version 7) would improve several areas; one of them: sorting and cursor-based pagination, which is arguably more efficient than offset-based pagination. Nonetheless, since rolling our own IDs is always an option, creating a new issue might be unnecessary.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1595