Blog | G5 Cyber Security

Random Column Names: Security & Data Protection

TL;DR

Using randomly generated column names in your databases can significantly improve security by making it harder for attackers to predict and exploit your data structure. It also helps with compliance and reduces the risk of accidental data exposure.

Why Use Random Column Names?

Traditionally, database columns have descriptive names like ‘customer_name’, ‘order_date’, or ’email_address’. While convenient for developers, these predictable names are a goldmine for attackers. Here’s why:

How to Implement Random Column Names

  1. Generate Unique Names: Create a function or script that generates unique, random strings for each column name. The length and complexity should be sufficient to prevent brute-force guessing (e.g., 16+ characters with mixed case letters, numbers, and symbols).
  2. import uuid
    
    def generate_column_name():
        return str(uuid.uuid4())[:16] # Generates a 16-character random string
    
  3. Mapping Table: Maintain a separate table (or configuration file) that maps the random column names to their actual meanings. This is crucial for developers and applications to understand the data.
  4. Example mapping table structure:

    Random Column Name Actual Meaning
    a1b2c3d4e5f6g7h8 customer_name
    i9j0k1l2m3n4o5p6 email_address
  5. Application Logic: Modify your application code to use the mapping table when interacting with the database. Instead of directly referencing ‘customer_name’, it should look up the corresponding random column name.
    # Example Python using a dictionary for the mapping
    mapping = {"a1b2c3d4e5f6g7h8": "customer_name", "i9j0k1l2m3n4o5p6": "email_address"}
    
    def get_data(column_meaning):
        if column_meaning in mapping:
            return mapping[column_meaning]
        else:
            return None # Handle cases where the meaning isn't found
    
  6. Database Creation Scripts: Integrate the random name generation into your database creation scripts. This ensures that all new columns are automatically assigned random names.

    For example, in PostgreSQL:

    CREATE TABLE customers (
        id SERIAL PRIMARY KEY,
        name VARCHAR(255) AS (generate_column_name()),
        email VARCHAR(255) AS (generate_column_name())
    );
    
  7. Regular Rotation: Consider periodically rotating the random column names. This adds another layer of security, as even if an attacker discovers the current mapping, it will eventually become outdated.

Considerations

Exit mobile version