Configurationο
django-honeyguard can be configured using either a dictionary-style configuration or individual settings. All settings are optional and have sensible defaults.
Configuration Methodsο
Method 1: Dictionary Configurationο
The recommended approach is to use a HONEYGUARD dictionary in your settings.py:
HONEYGUARD = {
"EMAIL_RECIPIENTS": ["admin@example.com"],
"EMAIL_SUBJECT_PREFIX": "π¨ Honeypot Alert",
"ENABLE_CONSOLE_LOGGING": True,
"LOG_LEVEL": "INFO",
}
Method 2: Individual Settingsο
You can also use individual HONEYGUARD_* settings:
HONEYGUARD_EMAIL_RECIPIENTS = ["admin@example.com"]
HONEYGUARD_EMAIL_SUBJECT_PREFIX = "π¨ Honeypot Alert"
HONEYGUARD_ENABLE_CONSOLE_LOGGING = True
Note
If both methods are used, the dictionary configuration takes priority over individual settings.
Available Settingsο
Email Configurationο
- EMAIL_RECIPIENTSο
Type:
List[str]Default:[]Description: List of email addresses to receive honeypot alerts.HONEYGUARD = { "EMAIL_RECIPIENTS": [ "admin@example.com", "security@example.com", ], }
If empty, email alerts will be disabled.
- EMAIL_SUBJECT_PREFIXο
Type:
strDefault:"π¨ Honeypot Alert"Description: Prefix for email alert subject lines.HONEYGUARD = { "EMAIL_SUBJECT_PREFIX": "[Security Alert]", }
- EMAIL_FROMο
Type:
str | NoneDefault:NoneDescription: From address for email alerts. IfNone, uses DjangoβsDEFAULT_FROM_EMAIL.HONEYGUARD = { "EMAIL_FROM": "security@example.com", }
- EMAIL_FAIL_SILENTLYο
Type:
boolDefault:TrueDescription: IfTrue, email sending errors wonβt raise exceptions.
Logging Configurationο
- ENABLE_CONSOLE_LOGGINGο
Type:
boolDefault:TrueDescription: Enable console logging of honeypot triggers.HONEYGUARD = { "ENABLE_CONSOLE_LOGGING": False, # Disable console logs }
- LOG_LEVELο
Type:
strDefault:"WARNING"Valid Values:"DEBUG","INFO","WARNING","ERROR"Description: Logging level for console output.HONEYGUARD = { "LOG_LEVEL": "WARNING", # Only log warnings and errors }
Timing Attack Detectionο
- TIMING_TOO_FAST_THRESHOLDο
Type:
floatDefault:2.0Description: Minimum time in seconds considered normal for form submission. Submissions faster than this are flagged.HONEYGUARD = { "TIMING_TOO_FAST_THRESHOLD": 3.0, # Require at least 3 seconds }
- TIMING_TOO_SLOW_THRESHOLDο
Type:
floatDefault:600.0Description: Maximum time in seconds before form submission is considered suspiciously slow.HONEYGUARD = { "TIMING_TOO_SLOW_THRESHOLD": 1200.0, # 20 minutes }
GET Method Detectionο
- ENABLE_GET_METHOD_DETECTIONο
Type:
boolDefault:FalseDescription: IfTrue, GET requests to admin URLs trigger honeypot detection.HONEYGUARD = { "ENABLE_GET_METHOD_DETECTION": False, # Only detect POST requests }
Form Field Configurationο
- MAX_USERNAME_LENGTHο
Type:
intDefault:150Description: Maximum length for Django admin username fields.
- MAX_PASSWORD_LENGTHο
Type:
intDefault:128Description: Maximum length for Django admin password fields.
- WORDPRESS_USERNAME_MAX_LENGTHο
Type:
intDefault:60Description: Maximum length for WordPress username fields.
- WORDPRESS_PASSWORD_MAX_LENGTHο
Type:
intDefault:255Description: Maximum length for WordPress password fields.
Error Messagesο
- DJANGO_ERROR_MESSAGEο
Type:
strDefault:"Please enter a correct username and password."Description: Error message shown when Django admin honeypot is triggered.HONEYGUARD = { "DJANGO_ERROR_MESSAGE": "Invalid credentials.", }
- WORDPRESS_ERROR_MESSAGEο
Type:
strDefault:"Invalid username or password."Description: Error message shown when WordPress admin honeypot is triggered.
Configuration Validationο
django-honeyguard validates all configuration settings at application startup. Invalid settings will raise django.core.exceptions.ImproperlyConfigured with a clear error message.
Example errors and fixes:
Invalid email recipient:
HONEYGUARD = {
"EMAIL_RECIPIENTS": "not-a-list", # β Wrong: should be a list
}
# β
Correct:
HONEYGUARD = {
"EMAIL_RECIPIENTS": ["admin@example.com"],
}
Invalid timing threshold:
HONEYGUARD = {
"TIMING_TOO_FAST_THRESHOLD": -5, # β Wrong: must be positive
}
# β
Correct:
HONEYGUARD = {
"TIMING_TOO_FAST_THRESHOLD": 2.0,
}
Invalid log level:
HONEYGUARD = {
"LOG_LEVEL": "VERBOSE", # β Wrong: not a valid level
}
# β
Correct:
HONEYGUARD = {
"LOG_LEVEL": "DEBUG",
}
Complete Exampleο
Hereβs a complete configuration example for a production environment:
# settings.py
HONEYGUARD = {
# Email alerts
"EMAIL_RECIPIENTS": [
"security@example.com",
"admin@example.com",
],
"EMAIL_SUBJECT_PREFIX": "[Honeypot Alert]",
"EMAIL_FROM": "security@example.com",
"EMAIL_FAIL_SILENTLY": False, # Raise on email errors in production
# Logging
"ENABLE_CONSOLE_LOGGING": True,
"LOG_LEVEL": "WARNING",
# Timing detection
"TIMING_TOO_FAST_THRESHOLD": 2.0,
"TIMING_TOO_SLOW_THRESHOLD": 600.0,
# Detection options
"ENABLE_GET_METHOD_DETECTION": True,
# Custom messages
"DJANGO_ERROR_MESSAGE": "Invalid credentials.",
"WORDPRESS_ERROR_MESSAGE": "Invalid username or password.",
}
# Ensure Django can send emails
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.example.com"
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = "security@example.com"
EMAIL_HOST_PASSWORD = "your-password"
DEFAULT_FROM_EMAIL = "security@example.com"