Validation and sanitization for plugin configuration inputs#7
Validation and sanitization for plugin configuration inputs#7AbdulDavids merged 7 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR enhances input validation and error handling across the plugin system by introducing a centralized validation module and improving error message display in the UI.
- Adds a new
security/validation.pymodule with comprehensive input sanitization and validation functions - Integrates validation into ModLog and AutoResponder plugins with proper authentication checks
- Implements auto-hiding error messages in the UI with smooth transitions
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| security/validation.py | New validation module providing sanitization and validation functions for channel identifiers, regex patterns, templates, and API keys |
| security/init.py | Exports the new validation module |
| plugins/modlog/plugin.py | Adds input validation for channel identifiers with authentication requirements |
| plugins/autoresponder/plugin.py | Integrates validation for rules, templates, and AI settings with authentication and error handling |
| plugins/autoresponder/templates/tab.html | Adds error message display with styling and auto-hide script |
| plugins/autoresponder/templates/greeter_tab.html | Adds error message display with styling and auto-hide script |
| static/admin/error-message.js | New script to auto-hide error messages after 5 seconds |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| """Sanitize system prompt.""" | ||
|
|
There was a problem hiding this comment.
The docstring is too brief. It should explain what the function does more completely, such as 'Sanitize system prompt text for AI configuration.'
| """Sanitize system prompt.""" | |
| """ | |
| Sanitize system prompt text for AI configuration. | |
| This function removes null bytes, trims leading and trailing whitespace, | |
| enforces a maximum length, and ensures the input is a non-empty string. | |
| Args: | |
| text (str): The system prompt text to sanitize. | |
| max_length (int): The maximum allowed length of the prompt (default: 5000). | |
| Returns: | |
| str: The sanitized system prompt text. | |
| Raises: | |
| ValueError: If the input is not a string, is empty after sanitization, | |
| or exceeds the maximum allowed length. | |
| """ |
|
|
||
|
|
||
| def sanitize_channel_suggestions(text: str, max_length: int = 2000) -> str: | ||
| """Sanitize channel suggestions.""" |
There was a problem hiding this comment.
The docstring is too brief. It should explain what the function does more completely, such as 'Sanitize channel suggestions text input.'
| """Sanitize channel suggestions.""" | |
| """ | |
| Sanitize user-provided channel suggestions text input by removing null bytes, | |
| trimming whitespace, and enforcing a maximum length. Returns the sanitized string, | |
| or an empty string if the input is empty after sanitization. | |
| Raises a ValueError if the input is not a string or exceeds the maximum length. | |
| """ |
| if raw_model.strip(): | ||
| model = sanitize_model_identifier(raw_model, max_length=50) | ||
| else: | ||
| model = DEFAULT_AI_GREETER_SETTINGS["model"] | ||
| if raw_system_prompt.strip(): |
There was a problem hiding this comment.
The .strip() operation is called twice on raw_model and raw_system_prompt - once in the conditional check and again inside the sanitize functions. This is redundant since the sanitize functions already strip the input. Consider checking the raw values directly or storing the stripped result.
| if raw_model.strip(): | |
| model = sanitize_model_identifier(raw_model, max_length=50) | |
| else: | |
| model = DEFAULT_AI_GREETER_SETTINGS["model"] | |
| if raw_system_prompt.strip(): | |
| if raw_model: | |
| model = sanitize_model_identifier(raw_model, max_length=50) | |
| else: | |
| model = DEFAULT_AI_GREETER_SETTINGS["model"] | |
| if raw_system_prompt: |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
No description provided.