Skip to content

Validation and sanitization for plugin configuration inputs#7

Merged
AbdulDavids merged 7 commits intomainfrom
validation-and-sanitization
Oct 29, 2025
Merged

Validation and sanitization for plugin configuration inputs#7
AbdulDavids merged 7 commits intomainfrom
validation-and-sanitization

Conversation

@JoshuaWood13
Copy link
Contributor

No description provided.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py module 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.

Comment on lines +152 to +153
"""Sanitize system prompt."""

Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring is too brief. It should explain what the function does more completely, such as 'Sanitize system prompt text for AI configuration.'

Suggested change
"""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.
"""

Copilot uses AI. Check for mistakes.


def sanitize_channel_suggestions(text: str, max_length: int = 2000) -> str:
"""Sanitize channel suggestions."""
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring is too brief. It should explain what the function does more completely, such as 'Sanitize channel suggestions text input.'

Suggested change
"""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.
"""

Copilot uses AI. Check for mistakes.
Comment on lines +547 to +551
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():
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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:

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
AbdulDavids and others added 2 commits October 29, 2025 21:15
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@AbdulDavids AbdulDavids merged commit 1a44136 into main Oct 29, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants