Browse Source

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

Jeremy Stretch 20 hours ago
parent
commit
7462e45c8e

+ 3 - 3
docs/configuration/development.md

@@ -4,9 +4,9 @@
 
 
 Default: `False`
 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
 !!! warning
     Never enable debugging on a production system, as it can expose sensitive data to unauthenticated users and impose a
     Never enable debugging on a production system, as it can expose sensitive data to unauthenticated users and impose a

+ 7 - 0
docs/configuration/system.md

@@ -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
 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`).
 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
 ## ISOLATED_DEPLOYMENT

+ 0 - 4
netbox/netbox/configuration_example.py

@@ -154,10 +154,6 @@ EXEMPT_VIEW_PERMISSIONS = [
 #     'https': 'http://10.10.1.10:1080',
 #     '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:
 # Enable custom logging. Please see the Django documentation for detailed guidance on configuring custom logs:
 #   https://docs.djangoproject.com/en/stable/topics/logging/
 #   https://docs.djangoproject.com/en/stable/topics/logging/
 LOGGING = {}
 LOGGING = {}

+ 4 - 0
netbox/netbox/settings.py

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

+ 24 - 0
netbox/utilities/debug.py

@@ -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