Explorar el Código

Fixes #23502: Add an example Content Security Policy page to the administration docs

The page gives operators a policy they can copy into SECURE_CSP, says what each directive allows, and explains testing with report-only mode. It states that NetBox's nonce rule covers scripts only and that inline styles are allowed by the example.
Jason Novinger hace 2 días
padre
commit
6373cdfeea
Se han modificado 2 ficheros con 31 adiciones y 0 borrados
  1. 30 0
      docs/administration/content-security-policy.md
  2. 1 0
      mkdocs.yml

+ 30 - 0
docs/administration/content-security-policy.md

@@ -0,0 +1,30 @@
+# Content Security Policy
+
+!!! info "This feature was introduced in NetBox v4.8."
+
+A [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP) (CSP) tells the browser from which sources a page may load scripts, images, fonts, and other resources. NetBox does not send one by default. To send one, define it with the [`SECURE_CSP`](../configuration/security.md#secure_csp) or [`SECURE_CSP_REPORT_ONLY`](../configuration/security.md#secure_csp_report_only) configuration parameter.
+
+NetBox's own pages are written to work under a strict script policy. Every `<script>` element NetBox renders carries the per-request nonce, and NetBox does not use inline event handler attributes or evaluate strings as code. This applies to scripts only. NetBox makes no equivalent promise for styles: it renders inline `<style>` elements and `style=` attributes, and none of them carry a nonce.
+
+## Example policy
+
+```python
+from django.utils.csp import CSP
+
+SECURE_CSP = {
+    'default-src': [CSP.SELF],
+    'script-src': [
+        CSP.SELF,
+        CSP.NONCE,
+        'https://static.copilot.netboxlabs.ai',
+    ],
+    'style-src': [CSP.SELF, CSP.UNSAFE_INLINE, 'https://fonts.googleapis.com'],
+    'font-src': [CSP.SELF, 'data:', 'https://fonts.gstatic.com'],
+    'img-src': [CSP.SELF, 'data:', 'https:'],
+    'connect-src': [CSP.SELF],
+    'worker-src': [CSP.SELF, 'blob:'],
+    'base-uri': [CSP.SELF],
+}
+```
+
+Try a policy first by assigning it to `SECURE_CSP_REPORT_ONLY`, which reports violations in the browser console without blocking anything.

+ 1 - 0
mkdocs.yml

@@ -173,6 +173,7 @@ nav:
             - Microsoft Entra ID: 'administration/authentication/microsoft-entra-id.md'
             - Okta: 'administration/authentication/okta.md'
         - Permissions: 'administration/permissions.md'
+        - Content Security Policy: 'administration/content-security-policy.md'
         - Error Reporting: 'administration/error-reporting.md'
         - Management Commands: 'administration/management-commands.md'
         - Replicating NetBox: 'administration/replicating-netbox.md'