An ID card with a UUID and a shield

UUIDs explained: identifiers are not authorization

UUIDs are useful labels for records, but they should not be mistaken for access controls or a complete data model. A UUID answers one question well: which record is this? It does not answer who is allowed to see it, whether the request is authentic, or whether the value is safe to trust. This guide explains what UUIDs are, how the common versions differ, and how to use them without accidentally turning an identifier into a password.

A UUID, or Universally Unique Identifier, is a 128-bit value usually written as 32 hexadecimal characters in five groups, separated by hyphens, for example 550e8400-e29b-41d4-a716-446655440000. The format is standardised, and the same format can be produced by browsers, servers, databases, and command-line tools. That portability is a large part of why UUIDs are popular: two systems can each generate identifiers without coordinating, and the chance of a collision is extremely low when the values are generated correctly.

What a UUID actually guarantees

A well-generated UUID is practically unique. For random UUIDs, the guarantee is statistical, not absolute: there are so many possible values that two independently generated ones are very unlikely to collide. It is not a guarantee that the value is secret, unpredictable to a determined attacker in every version, or tied to a particular user. Those properties depend on the version, the generator, and the checks around it.

Think of a UUID like a serial number on a parcel. The number lets the warehouse find the right parcel, and it avoids confusion between two parcels with similar addresses. It does not prove that the person holding the number owns the parcel, and printing the number on the outside does not make the contents private. If the system hands over the parcel to anyone who recites the number, the serial number has become the only lock, and that is a design flaw.

The common UUID versions

UUIDs have versions, and the version is encoded in the value itself. The most widely used versions are described in RFC 9562, which replaced the older RFC 4122. Knowing the version helps you choose the right one and avoid surprises.

Version 1 is based on a timestamp and a node identifier, historically a MAC address. It is sortable by time, but it can leak timing and machine information, so it is rarely the best choice for new public identifiers.

Version 4 is random. Most of the bits are generated from a secure random source, with a few bits fixed to mark the version and variant. This is the version most people mean when they say UUID, and it is a good default when you need an opaque identifier with no embedded meaning.

Version 3 and version 5 are name-based: they are derived by hashing a namespace plus a name, using MD5 for v3 and SHA-1 for v5. The same inputs always produce the same UUID, which is useful for deterministic identifiers, but it means the value is not secret if the inputs are known or guessable.

Version 6 and version 7 are newer time-ordered versions. Version 7 in particular combines a Unix timestamp in milliseconds with random bits, so values sort roughly in creation order while remaining largely unpredictable. Time-ordered UUIDs can improve database index performance compared with fully random values, because new rows land near each other rather than scattered across the index.

When you choose, document the decision. Record which version you use, who generates it, and whether it appears in URLs, logs, or exports. A future maintainer should not have to guess whether an identifier is random, time-ordered, or derived from a name.

What UUIDs are good for

UUIDs work well as primary keys and external references when you need identifiers that can be created in different places without a central counter. They are useful for distributed systems, offline clients, event logs, and integrations where two services each create records that later need to be merged.

They also help when you do not want to expose a sequential count. An order numbered 1024 tells a visitor roughly how many orders exist. A UUID does not. That is a privacy and business benefit, but it is not a security control on its own: hiding the count is not the same as protecting the record.

UUIDs are also useful as idempotency keys and correlation IDs. If a client retries a request, the same idempotency key lets the server recognise the retry and avoid creating a duplicate. If a request flows through several services, a correlation ID lets you follow the same operation across logs. In both cases, the UUID is a label for tracking, not a proof of permission.

Identifiers are not authorization

This is the central point of this guide. Authorization means checking whether the current user is allowed to perform an action on a resource. Authentication means checking who the user is. An identifier does neither. If your API returns a private document to anyone who presents the right UUID, then the UUID is functioning as a password, and a weak one at that, because UUIDs are often shared in URLs, logs, emails, screenshots, and support tickets.

Unpredictability is not authorization either. A version 4 UUID has about 122 bits of randomness, which is far too many to guess by brute force in practice. But attackers do not need to guess it if it leaks. A single forwarded email, a browser history entry, a referrer header, or a log file can hand the value to someone else. Security that depends on a value never leaking is fragile, because identifiers are designed to be shared and referenced, not kept secret.

The correct pattern is to separate the two concerns. Use the UUID to say which record you mean, and use a separate authentication and authorization check to decide whether the requester may access it. In a web application, that usually means: verify the session or token, load the record by UUID, check that the current user owns the record or has a role that permits access, and only then return or change it. If any step fails, return a generic not-found or forbidden response rather than revealing whether the UUID exists.

Worked example: an order lookup that checks permission

Step Safe flow
1. Verify authentication Session or token valid, belongs to a real user
2. Load the order By UUID from the database
3. Check permission Owner matches, or a role such as support agent permits it
4. Return details Only if the owner matches or the role permits it

Suppose an online shop stores orders with UUIDs, and a signed-in customer requests order 550e8400-e29b-41d4-a716-446655440000. A safe flow looks like this. First, the server verifies the request is authenticated: the session or token is valid and belongs to a real user. Second, it loads the order by UUID from the database. Third, it compares the order owner with the current user, or checks a role such as support agent with a legitimate reason. Fourth, only if the owner matches or the role permits it does the server return the order details.

Now consider the unsafe version: the server loads the order by UUID and returns it to anyone who asks, with no session check. That endpoint will appear to work in testing, and it may even pass a demo, because the tester happens to be the owner. In production, anyone who obtains a single order UUID, from a shared link, an email receipt, or a log, can read someone else order. The fix is not to make the UUID longer or stranger. The fix is to add the ownership check.

The same principle applies to updates and deletes. A request to cancel, refund, or change an order must pass the same authorization check as a read, and it should be logged. Also be careful with enumeration: if your API returns different responses for existing versus non-existing UUIDs, an attacker can probe which UUIDs exist. For sensitive resources, returning the same generic response for missing and forbidden records is often the safer choice.

Generating, validating, storing, and indexing

Generate UUIDs with a secure random source, not with a hand-rolled random function or a timestamp alone. In the browser, the standard crypto API provides a random UUID function. On the server, use your language or database built-in generator. Document whether values are generated by the browser, a service, or a database, because that affects trust: a client-generated identifier should be treated as untrusted input until the server validates it.

Always validate UUIDs at the boundary. Check the format, length, and version before using the value in a query, and use parameterised queries rather than string concatenation. Validation does not make a UUID safe to trust for authorization, but it prevents malformed input from causing errors or injection problems. Decide how to handle duplicates: a primary-key or unique constraint should reject a duplicate rather than silently overwriting a record, and your code should handle that rejection cleanly.

For storage, be consistent. Many systems store UUIDs as text, which is simple and readable but larger and slower to index than binary. Others store them as 16 bytes, which is more compact but harder to inspect. Either choice can work; the important part is to pick one format, use it everywhere, and test how your database compares and indexes the values. For large tables, test with realistic data volumes: random UUIDs can fragment indexes, while time-ordered UUIDs such as version 7 often insert more efficiently. Do not assume a generator alone proves how another system will store or compare the value.

Common mistakes to avoid

  • Treating a UUID as a secret, password, or access token, and returning private data to anyone who presents it.
  • Using a predictable or sequential generator where an opaque identifier was intended.
  • Embedding sensitive data, user details, or internal meaning in the UUID and assuming it stays hidden.
  • Accepting UUIDs from clients without validation, or building queries by concatenating them into SQL.
  • Logging UUIDs alongside sensitive data, or exposing them in URLs that get shared, without considering who can see them.
  • Mixing versions, formats, and casing across services without a documented standard.

Limitations

UUIDs do not provide authentication, authorization, encryption, or integrity. They do not prove that a value was created by your system, that it has not been tampered with, or that the requester is allowed to use it. They also do not solve data modelling on their own: you still need to decide what the record means, how it relates to other records, and how long it is kept. A UUID generator cannot prove how another system will store, compare, or index the value, so test those behaviours in the application that owns the records. This guide is general information, not security advice for a specific system; follow your organisation policy and consider professional review for sensitive systems.

Quick checklist

  • Choose and document a UUID version, generator, and storage format for each system.
  • Use the UUID only to identify the record; check authentication and authorization separately.
  • Validate UUID input at the boundary and use parameterised queries.
  • Enforce uniqueness with a constraint and handle duplicate rejections cleanly.
  • Test indexing, sorting, and collision handling with realistic data volumes.
  • Avoid putting sensitive data in identifiers, logs, or shareable URLs.

Use the related tool carefully

This guide is paired with a browser-only utility. The tool is a practical aid for small examples and inspection; it is not a substitute for application testing, a formal data pipeline, or professional review where the decision has higher consequences.

Open the related UUID v4 Generator

Related tools in this category

Frequently asked questions

Are UUIDs unique?

For practical purposes, yes, when they are generated correctly. Random UUIDs have so many possible values that collisions are extremely unlikely. Uniqueness is still statistical, not guaranteed by the format alone, so enforce it with a unique constraint in your database and handle a duplicate gracefully if one ever occurs.

Can I use a UUID as a password or access token?

No. A UUID is an identifier, not a credential. Identifiers are meant to be referenced, shared, and logged, which makes them a poor secret. Use proper authentication tokens, session handling, and authorization checks instead, and keep real secrets in a dedicated secrets store with rotation and expiry.

Which UUID version should I use?

Version 4 is a safe default for an opaque random identifier. Version 7 is a good choice when you want time-ordered values that index well and still contain random bits. Version 5 is useful when you need the same name to always produce the same identifier. Avoid version 1 for new public identifiers unless you have a specific reason, because it can leak timing and machine information.

Why do UUIDs appear in URLs if they are not secure?

Because URLs need a way to name a resource, and a UUID is a convenient, non-sequential name. Appearing in a URL does not mean the value is public or that anyone with it may access the resource. The server must still check authentication and authorization on every request, even when the identifier looks random and hard to guess.

Sources