All projects

Disid

Disguise ID values, transforming them from sequential integers to random looking values in a reversible one to one mapping.

Sequential IDs in URLs leak information and look unpolished. DisID maps integers to random-looking strings like WxYRW and back again. The transform is reversible and needs no database lookup; an optional static key file can be shared between every process that converts IDs.

  • Guarantees no duplicate obfuscated keys as well as a full saturation of allowed keyspace.
  • Databaseless operation with optional static key file sharing.

How It Works

DisID uses a reversible mathematical transformation:

from disid import DisID

# Create obfuscator with optional key file
obfuscator = DisID(key_file='secrets/disid.key')

# Convert ID to obfuscated string
obfuscated = obfuscator.encode(12345)
# Returns: 'WxYRW'

# Convert back to original
original = obfuscator.decode('WxYRW')
# Returns: 12345

Key Features

  • Reversible: Encode and decode without a database
  • Uniform: Full keyspace coverage, no gaps
  • Configurable: Length and character set control
  • Secure: Optional key file for encryption

Examples

URL Parameter Obfuscation

@app.route('/user/<int:user_id>')
def user_profile(user_id):
    token = obfuscator.encode(user_id)
    return render_template('profile.html', token=token)

@app.route('/user/<token>')
def decode_user(token):
    user_id = obfuscator.decode(token)
    return user_profile(user_id)

API Response Obfuscation

def serialize_user(user):
    return {
        'id': obfuscator.encode(user.id),
        'name': user.name
    }