| name | django-security-audit |
| description | Perform a security audit on a Django project |
| disable-model-invocation | true |
| allowed-tools | Read, Bash, Grep, Glob |
Django Security Audit
Execute each section of this audit systematically. Report findings by severity.
1. Settings Audit
Run Django's Built-in Check
python manage.py check --deploy
This checks for common security misconfigurations. Fix all warnings.
Critical Settings
Check config/settings/production.py for these settings:
grep -rn "SECRET_KEY\|DEBUG\|ALLOWED_HOSTS\|SECURE_\|CSRF_\|SESSION_\|HSTS" config/settings/
Must verify:
CSP Configuration (Django 6.0+)
Password Configuration
grep -rn "AUTH_PASSWORD_VALIDATORS" config/settings/
CORS Configuration
grep -rn "CORS_" config/settings/
2. Code Vulnerability Scan
XSS (Cross-Site Scripting)
grep -rn "mark_safe" --include="*.py" .
grep -rn "|safe" --include="*.html" .
grep -rn "format_html" --include="*.py" .
SQL Injection
grep -rn "\.raw(" --include="*.py" .
grep -rn "cursor\.execute" --include="*.py" .
grep -rn "\.extra(" --include="*.py" .
grep -rn "RawSQL" --include="*.py" .
CSRF
grep -rn "csrf_exempt" --include="*.py" .
grep -rn "method=\"post\"\|method='post'" --include="*.html" . | while read line; do
file=$(echo "$line" | cut -d: -f1)
grep -L "csrf_token" "$file" 2>/dev/null
done
Mass Assignment
grep -rn 'fields.*=.*"__all__"\|fields.*=.*__all__' --include="*.py" .
grep -rn "exclude\s*=" --include="*.py" .
File Upload Security
grep -rn "FileField\|ImageField" --include="*.py" .
3. Authentication Audit
User Model
grep -rn "AUTH_USER_MODEL" config/settings/
Session Management
Admin Security
grep -rn "admin.site.urls\|admin/" config/urls.py
API Authentication
grep -rn "DEFAULT_AUTHENTICATION_CLASSES\|authentication_classes" --include="*.py" .
4. Dependency Audit
pip-audit
safety check
python -c "import django; print(django.VERSION)"
5. Information Leakage
grep -rn "DEBUG" --include="*.py" config/settings/production.py
grep -rn "handler404\|handler500" --include="*.py" .
grep -rn "debug_toolbar\|silk\|profiling" --include="*.py" config/
6. Secrets in Version Control
git log --all --diff-filter=A -- "*.env" ".env*" "*secret*" "*password*" "*token*" "*key*"
grep -rn "password\s*=\s*['\"]" --include="*.py" . | grep -v "test\|factory\|fixture"
grep -rn "token\s*=\s*['\"]" --include="*.py" . | grep -v "test\|factory\|fixture"
grep -rn "api_key\s*=\s*['\"]" --include="*.py" . | grep -v "test\|factory\|fixture"
Severity Levels
- CRITICAL: Exploitable vulnerability (SQL injection, exposed secrets, DEBUG=True in prod)
- HIGH: Security misconfiguration (missing HSTS, no CSP, weak passwords)
- MEDIUM: Best practice violation (mark_safe usage, no rate limiting)
- LOW: Improvement opportunity (dependency updates, additional headers)
Report Template
# Security Audit Report — [Project Name]
**Date:** YYYY-MM-DD
**Auditor:** Claude Code (django-security-audit)
## Summary
- Critical: N findings
- High: N findings
- Medium: N findings
- Low: N findings
## Findings
### [CRITICAL] Finding Title
**Location:** `path/to/file.py:42`
**Description:** ...
**Impact:** ...
**Remediation:** ...
### [HIGH] Finding Title
...