Skip to content

Allow enabling Django Debug Toolbar via env variable#12921

Merged
valentijnscholten merged 3 commits intoDefectDojo:bugfixfrom
valentijnscholten:debug-toolbar6
Sep 10, 2025
Merged

Allow enabling Django Debug Toolbar via env variable#12921
valentijnscholten merged 3 commits intoDefectDojo:bugfixfrom
valentijnscholten:debug-toolbar6

Conversation

@valentijnscholten
Copy link
Copy Markdown
Member

@valentijnscholten valentijnscholten commented Aug 4, 2025

This PR changes the importing of the extra urls for the debug toolbaar a bit to make it work with Django Debug Toolbar 6.0.0.

The debug toolbar is now also included by default in settings.dist.py, but in disabled state.

It can be enabled by setting `` to True. It's disabled by default, except when running in dev mode. Hopefully every PR author from now on will check the toolbar for any adverse performance effects :-)

@github-actions github-actions Bot added settings_changes Needs changes to settings.py based on changes in settings.dist.py included in this PR docs helm labels Aug 4, 2025
@github-actions
Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Sep 2, 2025

Conflicts have been resolved. A maintainer will review the pull request shortly.

@valentijnscholten valentijnscholten changed the base branch from master to bugfix September 2, 2025 17:25
@valentijnscholten valentijnscholten added this to the 2.50.1 milestone Sep 2, 2025
@valentijnscholten valentijnscholten marked this pull request as ready for review September 2, 2025 17:43
@valentijnscholten valentijnscholten changed the title Debug toolbar6 Allow enabling Django Debug Toolbar via env variable Sep 2, 2025
@valentijnscholten valentijnscholten marked this pull request as draft September 4, 2025 20:17
@valentijnscholten
Copy link
Copy Markdown
Member Author

converted back to draft as it doesn't work "anymore", will investigate.

@valentijnscholten valentijnscholten marked this pull request as ready for review September 5, 2025 14:00
@valentijnscholten
Copy link
Copy Markdown
Member Author

converted back to draft as it doesn't work "anymore", will investigate.

fixed

@dryrunsecurity
Copy link
Copy Markdown

dryrunsecurity Bot commented Sep 5, 2025

DryRun Security

This pull request leaves the Django Debug Toolbar configured to be unconditionally visible (the show_toolbar callback always returns True), so if DJANGO_DEBUG_TOOLBAR_ENABLED is set in a production environment it could expose sensitive debugging information. The issue is in dojo/settings/settings.dist.py where the toolbar visibility is effectively unrestricted.

Potential Information Disclosure via Debug Toolbar in dojo/settings/settings.dist.py
Vulnerability Potential Information Disclosure via Debug Toolbar
Description The Django Debug Toolbar is configured to be unconditionally visible if enabled, due to the show_toolbar callback always returning True. This means that if DJANGO_DEBUG_TOOLBAR_ENABLED is set to True in a production environment, sensitive debugging information (such as SQL queries, request/response data, and application settings) could be exposed to any visitor, leading to severe information disclosure.

warnings.filterwarnings("ignore", "The FORMS_URLFIELD_ASSUME_HTTPS transitional setting is deprecated.")
FORMS_URLFIELD_ASSUME_HTTPS = True
# Inspired by https://adamj.eu/tech/2023/12/07/django-fix-urlfield-assume-scheme-warnings/
if DEBUG:
# adding DEBUG logging for all of Django.
LOGGING["loggers"]["root"] = {
"handlers": ["console"],
"level": "DEBUG",
}
if DJANGO_DEBUG_TOOLBAR_ENABLED:
INSTALLED_APPS += (
"debug_toolbar",
)
MIDDLEWARE = ["debug_toolbar.middleware.DebugToolbarMiddleware", *MIDDLEWARE]
def show_toolbar(request):
return True
DEBUG_TOOLBAR_CONFIG = {
"SHOW_TOOLBAR_CALLBACK": show_toolbar,
"INTERCEPT_REDIRECTS": False,
"SHOW_COLLAPSED": True,
}
DEBUG_TOOLBAR_PANELS = [
# 'ddt_request_history.panels.request_history.RequestHistoryPanel', # Here it is
"debug_toolbar.panels.versions.VersionsPanel",
"debug_toolbar.panels.timer.TimerPanel",
"debug_toolbar.panels.settings.SettingsPanel",
"debug_toolbar.panels.headers.HeadersPanel",
"debug_toolbar.panels.request.RequestPanel",
"debug_toolbar.panels.sql.SQLPanel",
"debug_toolbar.panels.templates.TemplatesPanel",
# 'debug_toolbar.panels.staticfiles.StaticFilesPanel',
"debug_toolbar.panels.cache.CachePanel",
"debug_toolbar.panels.signals.SignalsPanel",
# 'debug_toolbar.panels.logging.LoggingPanel',
"debug_toolbar.panels.redirects.RedirectsPanel",
"debug_toolbar.panels.profiling.ProfilingPanel",
# 'cachalot.panels.CachalotPanel',
]


All finding details can be found in the DryRun Security Dashboard.

Copy link
Copy Markdown
Contributor

@Maffooch Maffooch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very elegant approach here - great work!

Copy link
Copy Markdown
Contributor

@mtesauro mtesauro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

@valentijnscholten valentijnscholten modified the milestones: 2.50.1, 2.50.2 Sep 9, 2025
@valentijnscholten valentijnscholten merged commit e464cbe into DefectDojo:bugfix Sep 10, 2025
84 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docker docs settings_changes Needs changes to settings.py based on changes in settings.dist.py included in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants