Skip to content

with DEBUG = True, database credentials (specifically the password) are displayed in clear text on Django’s technical 500 debug page. #282

@cesarbenjamindotnet

Description

@cesarbenjamindotnet

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

  1. Create a Django project with DEBUG = True
  2. Install and configure dj-database-url
  3. Configure the database using an environment variable, for example:

DATABASE_URL=postgres://user:supersecret@localhost:5432/mydb

  1. In settings.py:
import dj_database_url

DATABASES = {
    "default": dj_database_url.config()
}
  1. Trigger an unhandled exception so that Django’s technical 500 debug page is shown
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions