-
-
Notifications
You must be signed in to change notification settings - Fork 216
Description
When using dj-database-url in a Django project with DEBUG = True, database credentials (specifically the password) are displayed in clear text on Django’s technical 500 debug page.
Django’s debug page normally masks sensitive settings (e.g. passwords, secret keys) with ***********. This works as expected for many built-in settings, but database passwords parsed via dj-database-url are not masked and are fully visible in the error page.
This can lead to accidental credential exposure during development, debugging sessions, screen sharing, or error screenshots.
Steps to reproduce
- Create a Django project with DEBUG = True
- Install and configure dj-database-url
- Configure the database using an environment variable, for example:
DATABASE_URL=postgres://user:supersecret@localhost:5432/mydb
- In settings.py:
import dj_database_url
DATABASES = {
"default": dj_database_url.config()
}- Trigger an unhandled exception so that Django’s technical 500 debug page is shown
- Inspect the Settings section of the debug page
Observed behavior
In the debug page, under DATABASES, the database password is shown in clear text:
'DATABASES': {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'mydb',
'USER': 'user',
'PASSWORD': 'supersecret',
'HOST': 'localhost',
'PORT': '5432',
}
}Expected behavior
Sensitive credentials such as database passwords should be masked in the Django debug page (e.g. displayed as ***********), consistent with how Django handles other sensitive settings.
Why this matters
- Django developers reasonably expect secrets to be masked in the debug page
- dj-database-url is commonly used in local development, CI, and cloud-based environments
- The issue can lead to accidental leakage of credentials in logs, screenshots, or screen sharing sessions
- The behavior is surprising, as Django does mask other sensitive configuration values
Additional context
- This only affects Django’s debug error page
- Production behavior is not affected
- The issue appears to be related to how Django determines which settings are considered sensitive when rendering the debug page