Skip to main content

Secure Input Handling and Validation

The vault must validate names and avoid accepting overly large values or unexpected characters.

Example: validate entry name and limit size

import re

NAME_RE = re.compile(r'^[a-zA-Z0-9_\-]{1,64}$')

def validate_name(name):
if not NAME_RE.match(name):
raise ValueError("Invalid entry name.")
return name

def validate_value(value):
if len(value) > 5000:
raise ValueError("Value too long.")
return value

Lesson: Constrain inputs by pattern and size to reduce attack surface and accidental misuse.