DEBUG=True and other settings leaks
- With DEBUG on, a 404 lists the URL patterns and an unhandled error shows a full traceback with settings and local variables. Django filters values whose names look like secrets, but not all of them.
- ALLOWED_HOSTS = ['*'] combined with Host-header-based URL building enables password-reset poisoning.
- /admin/ at its default path invites credential stuffing; it should be rate limited or moved behind SSO.
- Static or media directories served by the app can expose uploaded files without access checks.
Where the ORM stops protecting you
Querysets are parameterised, but raw(), extra() and RawSQL with string formatting are not. Less obviously, passing request data as keyword arguments into filter() is risky: CVE-2025-64459 (November 2025) allowed SQL injection when a crafted dictionary reached QuerySet.filter(), exclude(), get() or Q() with the internal _connector argument. It was fixed in 5.2.8, 5.1.14 and 4.2.26. Earlier, CVE-2022-34265 affected Trunc() and Extract() with untrusted lookup names. Patterns like Model.objects.filter(**request.GET.dict()) deserve a direct test.
Django REST framework permissions
- IsAuthenticated on a viewset does not restrict which objects a user can fetch. get_queryset must be scoped, or has_object_permission must check ownership.
- Serializers with fields = '__all__' expose and accept every model field, which leads to excessive data exposure and mass assignment.
- DEFAULT_PERMISSION_CLASSES left as AllowAny means any view that forgets to override it is public.
Testing a Django app with Pentest-Swarm
Pentest-Swarm works on the deployed site over HTTP. It does not read settings.py; it finds what the running app reveals.
- Recon checks drf-spectacular style schema endpoints such as /api/schema/ and maps documented endpoints automatically.
- Run the owasp-top10 playbook for the website and api-security for DRF endpoints, with a test user's session cookie passed via
--cookie. - sqlmap is part of the arsenal; with
--verify, injection findings are confirmed by differential or timing oracles rather than taken on the model's word. - Scope the run to your staging host and exclude anything shared using
--exclude.
Where it falls short
A black-box test sees a debug page only if it can trigger one, and it cannot list every raw() call in your codebase. Run Django's own manage.py check --deploy, add a SAST tool for raw SQL and extra(), and keep Django patched; the ORM CVEs above are fixed by upgrading, not by testing.
Questions
Is Django's ORM safe from SQL injection?
Standard queryset methods are parameterised. raw(), extra(), RawSQL and passing untrusted dictionaries as keyword arguments are where injection has occurred, including the 2025 _connector CVE.
What does DEBUG=True expose in production?
URL patterns on 404 pages and detailed tracebacks with settings and local variables on errors. Even with Django's filtering of secret-looking names, it is valuable reconnaissance for an attacker.
Can automated testing check DRF object permissions?
Yes, by requesting objects owned by one test user while authenticated as another. You need at least two test accounts for that.