Module utils

Module utils 

Source
Expand description

Utility functions and helpers.

This module provides security-focused utilities with input validation and safe path handling to prevent common vulnerabilities.

Functionsยง

file_exists
Checks if a file exists and is readable with path validation. Returns false for invalid or potentially dangerous paths.
get_base_directory
Extracts the base directory from a file path.
get_file_extension
Gets the file extension from a path.
has_path_traversal
Checks if a path contains potential traversal sequences.
is_image_file
Validates that a path points to an image file.
is_markdown_file
Validates that a path points to a markdown file.
is_safe_path
Validates that a path is safe to access (prevents path traversal and dangerous files).
resolve_path
Resolves relative paths against a base directory with security validation. Prevents path traversal attacks by validating the resolved path.
sanitize_filename
Sanitizes a filename by removing or replacing dangerous characters.
validate_app_credentials
Validates WeChat app credentials format.
validate_file_size
Validates file size limits to prevent DoS attacks.