This chapter covers the core features and capabilities of Spam Prevention.
# Check a form submission for spam
python src/spam_prevention.py --check '{"email": "user@example.com", "message": "Buy cheap stuff now!!!"}'
# Generate a honeypot field
python src/spam_prevention.py --generate-honeypot
# Generate an HMAC timestamp token
python src/spam_prevention.py --generate-timestamp
# Block an IP address
python src/spam_prevention.py --block-ip 192.168.1.100
# Unblock an IP address
python src/spam_prevention.py --unblock-ip 192.168.1.100
# Run the built-in demo
python src/spam_prevention.py --demoFollow this guide to get Spam Prevention up and running in your environment.
| Flag | Description |
|---|---|
--check JSON | Check a submission JSON string for spam |
--generate-honeypot | Generate a hidden honeypot field HTML snippet |
--generate-timestamp | Generate an HMAC-signed timestamp token |
--block-ip IP | Add an IP to the blocklist |
--unblock-ip IP | Remove an IP from the blocklist |
--demo | Run a built-in demo of all spam prevention layers |
Hidden form fields invisible to real users but filled by bots:
<!-- Generated by spam_prevention.py -->
<div style="position:absolute;left:-9999px;" aria-hidden="true">
<input type="text" name="website_url_confirm" tabindex="-1" autocomplete="off">
</div>If the honeypot field has any value when submitted, the submission is flagged as spam.
A cryptographic token embedded in the form that encodes the timestamp:
JSON-file-backed per-IP rate limiting:
# Default: 5 submissions per 60 seconds per IP
rate_limiter = RateLimiter(max_requests=5, window_seconds=60)Block individual IPs or entire /24 subnets:
python src/spam_prevention.py --block-ip 192.168.1.100
python src/spam_prevention.py --block-ip 10.0.0.0/24Heuristic checks on submission content:
| Check | Description |
|---|---|
| Spam phrases | Detects common spam phrases ("buy now", "click here", etc.) |
| URL count | Flags submissions with excessive URLs |
| CAPS ratio | Flags text that's mostly UPPERCASE |
| Repetitive chars | Flags text with repeating character patterns |
Get the full Spam Prevention and unlock everything.
Get the complete guide with every chapter unlocked, including code samples, diagrams, and best practices.
Access all interactive tools with complete data, all workload profiles, and the full scenario library.
Downloadable source code, configuration files, and working examples from every chapter.
Free updates for life. Every new chapter, tool, and improvement included.