Skip to main content

validate_file_name

Validates a file name to prevent path traversal and ensure it does not contain dangerous components like empty strings or relative directory markers. Depending on the configuration, it either restricts the input to a simple base name or verifies that a relative path is safe and does not use absolute paths or parent directory references.

def validate_file_name(
name: string,
allow_relative_path: boolean = False
) - > string

Validates a file name to prevent path traversal attacks and ensure it does not contain dangerous directory references.

Parameters

NameTypeDescription
namestringThe file name or path string to be validated for security compliance.
allow_relative_pathboolean = FalseWhether to permit relative path components; if False, the name must be a simple file name without any directory elements.

Returns

TypeDescription
stringThe validated file name if it passes all security checks.