Q. Inquiry on Security Considerations When Using UUIDs

Details of the inquiry

I am in charge of the development team at a company that provides a streaming service on the cloud in SaaS form.
We have come to use UUIDs. Please tell us what security matters should be considered when designing or implementing them.

1. Security considerations
  • A UUID must be generated in a secure manner, and it must be generated on the server side rather than the client side in order to prevent prediction attacks and tampering attacks.
  • It must be generated using a secure random number generation algorithm. (The uuid4() function of Python’s uuid module, or the secrets module, provides this function.)
  • For UUID security, other security measures such as authentication, encryption, and access control must be used together in combination.
  • Before a UUID is stored in a database or other storage, it must be stored securely using hashing and salting.
  • In order to prevent input intended for a malicious purpose and to confirm that the format is correct, the server must validate the received UUID value.
  • A UUID must not be used in a URL or as a URL parameter, so that it is not abused for session hijacking or leakage of sensitive information.
2. Python example of UUID generation

# Example code -1 Example code that generates a random UUID using the uuid4() function

import uuid

new_uuid = uuid.uuid4()
print(f"The generated UUID is : {new_uuid}")

# Example code -2 Example code that generates a random UUID using the secrets module

import secrets

def generated_uuid():
   return secrets.token_hex(16)

# Example code -3 Example code using OWASP’s ESAPI framework
The ESAPI randomizer is used to generate a random UUID, and the ESAPI encoder is used to encode the UUID for secure storage

from esapi.encoder import Encoder
from esapi.randomizer import Randomizer

def generate_secure_uuid():
  # ESAPI encoder instance
  encoder = Encoder.get_instance()

  # ESAPI randomizer instance
  randomizer = Randomizer.get_instance()

  # Generate a random UUID with the ESAPI randomizer
  uuid = encoder.encode_for_string(randomizer.get_random_uuid().hex)

  return uuid

print(generate_secure_uuid())