Closes #21865: Display debug toolbar if INTERNAL_IPS is empty (#21871)

This commit is contained in:
Jeremy Stretch
2026-04-09 13:19:25 -04:00
committed by GitHub
parent cc03d509d1
commit 7462e45c8e
5 changed files with 38 additions and 7 deletions

View File

@@ -4,9 +4,9 @@
Default: `False`
This setting enables debugging. Debugging should be enabled only during development or troubleshooting. Note that only
clients which access NetBox from a recognized [internal IP address](./system.md#internal_ips) will see debugging tools in the user
interface.
This setting enables debugging and displays a debugging toolbar in the user interface. Debugging should be enabled only during development or troubleshooting.
Note that the debugging toolbar will be displayed only for requests originating from [internal IP addresses](./system.md#internal_ips), if defined. If no internal IPs are defined, the toolbar will be displayed for all requests.
!!! warning
Never enable debugging on a production system, as it can expose sensitive data to unauthenticated users and impose a

View File

@@ -105,6 +105,13 @@ A list of IP addresses recognized as internal to the system, used to control the
example, the debugging toolbar will be viewable only when a client is accessing NetBox from one of the listed IP
addresses (and [`DEBUG`](./development.md#debug) is `True`).
!!! info "New in NetBox v4.6"
Setting this parameter to an empty list will enable the toolbar for all requests provided debugging is enabled:
```python
INTERNAL_IPS = []
```
---
## ISOLATED_DEPLOYMENT

View File

@@ -154,10 +154,6 @@ EXEMPT_VIEW_PERMISSIONS = [
# 'https': 'http://10.10.1.10:1080',
# }
# IP addresses recognized as internal to the system. The debugging toolbar will be available only to clients accessing
# NetBox from an internal IP.
INTERNAL_IPS = ('127.0.0.1', '::1')
# Enable custom logging. Please see the Django documentation for detailed guidance on configuring custom logs:
# https://docs.djangoproject.com/en/stable/topics/logging/
LOGGING = {}

View File

@@ -587,6 +587,10 @@ SERIALIZATION_MODULES = {
'json': 'utilities.serializers.json',
}
DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': 'utilities.debug.show_toolbar',
}
#
# Permissions & authentication

24
netbox/utilities/debug.py Normal file
View File

@@ -0,0 +1,24 @@
from django.conf import settings
from django.http import HttpRequest
__all__ = (
'show_toolbar',
)
def show_toolbar(request: HttpRequest) -> bool:
"""
Override django-debug-toolbar's default display conditions to allow for an empty INTERNAL_IPS.
"""
if not settings.DEBUG:
return False
# If no internal IPs have been defined, enable the toolbar
if not settings.INTERNAL_IPS:
return True
# If the request is from an internal IP, enable the toolbar
if request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
return True
return False