openhands.server.file_config
sanitize_filename
def sanitize_filename(filename)
Sanitize the filename to prevent directory traversal
load_file_upload_config
def load_file_upload_config(
config: AppConfig = shared_config) -> tuple[int, bool, list[str]]
Load file upload configuration from the config object.
This function retrieves the file upload settings from the global config object. It handles the following settings:
- Maximum file size for uploads
- Whether to restrict file types
- List of allowed file extensions
It also performs sanity checks on the values to ensure they are valid and safe.
Returns:
tuple
- A tuple containing:- max_file_size_mb (int): Maximum file size in MB. 0 means no limit.
- restrict_file_types (bool): Whether file type restrictions are enabled.
- allowed_extensions (set): Set of allowed file extensions.
is_extension_allowed
def is_extension_allowed(filename)
Check if the file extension is allowed based on the current configuration.
This function supports wildcards and files without extensions. The check is case-insensitive for extensions.
Arguments:
filename
str - The name of the file to check.
Returns:
bool
- True if the file extension is allowed, False otherwise.