- Notifications
You must be signed in to change notification settings - Fork 0
Security
PluginForge includes security measures to prevent path traversal attacks and validate plugin names.
Plugin names are used to construct file paths (config/plugins/{name}.yaml). A malicious plugin name like ../../etc/passwd could read arbitrary files. PluginForge prevents this by validating all plugin names.
- Must start with a letter
- May contain letters, digits, underscores, or hyphens
- Maximum 64 characters
- No path separators (
/,\), dots (.), or spaces
Plugin names are validated automatically in:
load_plugin_config()- before loading plugin YAMLload_i18n()- before loading language YAMLregister_plugin()- before registering a plugin instance_activate_with_states()- during discovery/registration pipelines (renamed from_activate_orderedin v0.6.0)
Invalid names raise InvalidPluginNameError (a subclass of ValueError):
frompluginforgeimportInvalidPluginNameErrortry:
pm.register_plugin(evil_plugin)
exceptInvalidPluginNameErrorase:
print(f"Rejected: {e}")The load_plugin_config() and load_i18n() functions validate their name parameters before constructing file paths. This prevents directory traversal via plugin names or language codes.
Migration directories returned by get_migrations_dir() are resolved to absolute paths. Symlink chains are followed to their real location before being accepted.
Validate a plugin name. Raises InvalidPluginNameError if invalid.
frompluginforge.securityimportvalidate_plugin_namevalidate_plugin_name("my-plugin") # okvalidate_plugin_name("../etc/passwd") # raises InvalidPluginNameErrorCheck that a resolved path stays within an allowed base directory.
frompluginforge.securityimportvalidate_safe_pathvalidate_safe_path("/app/config/plugins/export.yaml", "/app/config") # Truevalidate_safe_path("/app/config/../../etc/passwd", "/app/config") # False- Always use
PluginManagermethods to load configs rather than constructing paths manually - If accepting plugin names from user input (e.g. a settings UI), the validation is automatic
- For custom file operations with plugin-derived paths, use
validate_safe_path()to check containment