Skip to content

ENHANCEMENT: Add comprehensive server-side input validation and sanitization #24

Description

@Senthil455

Description

Server-side input validation is minimal throughout the application. Most routes only check if parameters exist (non-null checks), but do not validate format, length, range, or sanitize input. This can lead to data integrity issues, security vulnerabilities, and poor user experience.

Current Validation (minimal)

# app.py - Registration route (line ~45)
name = request.form['name']
email = request.form['email']
password = request.form['password']
# No validation on name length, email format, password strength
# No sanitization
# app.py - create_quiz route (line ~810)
title = request.form['title']
# No validation on title length, character restrictions

Missing Validations

  1. Registration: Email format validation, password strength requirements (min length, complexity), name length limits
  2. Quiz creation: Title/description length limits, date range validation (availableto > availablefrom), difficulty validation
  3. Questions: Question text length, option validation (no duplicate options), correct answer must match an option
  4. Class creation: Class name format validation
  5. General: Server-side re-validation of client-side validated fields (client-side can be bypassed)

Recommended Enhancement

  1. Create a validation utility module with reusable validators:

    import re
    
    def validate_email(email):
        pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
        return re.match(pattern, email) is not None
    
    def validate_password_strength(password):
        return len(password) >= 8
    
    def sanitize_input(text, max_length=500):
        # Strip HTML tags, limit length, trim whitespace
        cleaned = re.sub(r'<[^>]*>', '', text)
        return cleaned.strip()[:max_length]
  2. Apply validations consistently across all routes, returning appropriate flash messages for invalid input

  3. Validate dates and numbers with proper type checking and range validation

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestsecuritySecurity vulnerability or concern

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions