Bulk Messaging System

An Electron Desktop app for marketing campaign & broadcast management, using either whatsapp, gmail or a SMTP server

Input validation and sanitization

Introduction#

Validation at IPC boundaries and in Python parsers: emails, phones, file types, and rejecting garbage before send.

  • Phone number normalization and validation
  • Email address extraction and filtering
  • User-provided content sanitization for messages
  • Security measures against malicious file uploads, CSV parsing risks, and command injection attempts
  • Input encoding strategies, escape sequence handling, and data integrity verification

Covers Electron main-process handlers and Python utilities: how inputs are checked, cleaned, and passed across the IPC boundary.

Project structure#

The application comprises:

  • Electron main process handlers for WhatsApp, Gmail, and SMTP operations
  • Frontend React components for user interaction
  • Python utilities for phone number cleaning and contact extraction
  • A Flask backend for file upload and user management

Core components#

This section outlines the primary validation and sanitization mechanisms implemented in the codebase.

  • Phone number cleaning and normalization

  • Removes separators and non-digit characters except plus sign

  • Enforces length constraints and optional international prefix

  • Standardizes local numbers to international format when applicable

  • Manual phone number parsing

  • Accepts multiple formats: standalone numbers, name:number pairs, and delimiter-separated entries

  • Uses regex heuristics to detect phone-like substrings

  • Produces normalized contacts with optional names

  • Contact extraction from files

  • Supports CSV, TXT, and Excel formats

  • Heuristic detection of phone and name columns

  • Reliable fallbacks and error handling for malformed inputs

  • Email list parsing

  • Reads CSV with flexible column names or plain text newline-separated entries

  • Filters entries containing “@” to approximate valid email addresses

  • Message sanitization

  • Limits message lengths for safety and performance

  • Encodes HTML content appropriately for transport

  • Avoids unsafe inline styles or scripts in HTML messages

  • File upload restrictions

  • Whitelists allowed file extensions

  • Uses secure filename generation

  • Stores uploads under controlled paths

Architecture overview#

The validation pipeline spans frontend, Electron main process, and Python utilities:

Detailed component analysis#

Phone number validation and normalization#

Phone numbers undergo strict cleaning and normalization:

  • Strips whitespace and common separators
  • Removes non-digit characters except “+”
  • Handles leading zeros and optional international prefixes
  • Validates digit count within accepted bounds

Manual phone number parsing#

The manual parser supports flexible input formats:

  • Standalone numbers
  • Name-number pairs separated by colon or dash
  • Delimiter-separated entries (newline, comma, semicolon, pipe)
  • Heuristic detection of phone-like substrings

Contact extraction from files#

File-based contact extraction supports multiple formats:

  • CSV: heuristic column detection for phone/name; reliable fallbacks
  • TXT: delimiter-separated lines with optional name
  • Excel: pandas-based parsing with similar heuristics

Email address parsing and filtering#

Email lists are parsed from CSV or plain text:

  • CSV: flexible column names (email, Email, ADDRESS, etc.) or first column fallback
  • Text: newline-separated entries filtered by presence of “@”
  • Transport encoding: HTML content-type header included

Message content sanitization#

Message composition includes:

  • Length limits for performance and platform constraints
  • HTML content-type header for Gmail transport
  • Optional HTML stripping for text version in SMTP

File upload security measures#

The Flask backend enforces:

  • Allowed file extensions whitelist
  • Secure filename generation
  • Controlled upload path
  • JSON responses for API endpoints

Dependency analysis#

Key dependencies and interactions:

  • Frontend components communicate with Electron main process via contextBridge
  • Pyodide loads Python scripts dynamically for manual number parsing
  • Handlers depend on environment variables for external services
  • File parsing relies on pandas for structured formats

Performance considerations#

  • Regex-based cleaning and parsing are efficient for typical contact volumes but should be monitored for very large inputs
  • File parsing uses streaming for CSV; ensure appropriate buffering and memory limits
  • Message length limits prevent excessive payload sizes and reduce transport overhead
  • Rate limiting delays in email sending avoid throttling and improve reliability

Troubleshooting guide#

Common validation and sanitization issues:

  • Invalid phone numbers

  • Cause: Non-digit characters outside “+”, incorrect length

  • Resolution: Ensure numeric input with optional “+” prefix and correct digit count

  • Malformed CSV/Excel files

  • Cause: Missing headers, unexpected delimiters, mixed encodings

  • Resolution: Validate schema and encoding; provide clear error messages

  • Email parsing failures

  • Cause: Missing “@” or unsupported column names

  • Resolution: Use supported column names or rely on first-column fallback

  • File upload errors

  • Cause: Unsupported extension or missing file part

  • Resolution: Confirm allowed extensions and proper multipart form submission

Conclusion#

Validate in main and in Python even if the UI already checked. The renderer is not a trust boundary.