{% block javascript scoped %}
{{ super() }}
-
{% endblock %}
From ff68db540f100fa7718cf5bd1f8f3d0a6d5f176b Mon Sep 17 00:00:00 2001
From: Wyatt Pearsall
Date: Fri, 27 Sep 2024 13:30:32 -0700
Subject: [PATCH 2/3] Don't set CSP for wagtail admin pages and override
userbar
---
cfgov/cfgov/settings/base.py | 1 +
.../templates/wagtailadmin/userbar/base.html | 41 +++++++++++++++++++
2 files changed, 42 insertions(+)
create mode 100644 cfgov/wagtailadmin_overrides/templates/wagtailadmin/userbar/base.html
diff --git a/cfgov/cfgov/settings/base.py b/cfgov/cfgov/settings/base.py
index d65e2f3a6f4..a040298cbf0 100644
--- a/cfgov/cfgov/settings/base.py
+++ b/cfgov/cfgov/settings/base.py
@@ -485,6 +485,7 @@
CSP_OBJECT_SRC = ("'none'")
CSP_BASE_URI = ("'none'")
CSP_INCLUDE_NONCE_IN = ["script-src"]
+CSP_EXCLUDE_URL_PREFIXES = ("/admin")
# FEATURE FLAGS
# Flags can be declared here with an empty list, which will evaluate as false
diff --git a/cfgov/wagtailadmin_overrides/templates/wagtailadmin/userbar/base.html b/cfgov/wagtailadmin_overrides/templates/wagtailadmin/userbar/base.html
new file mode 100644
index 00000000000..80299cd7e64
--- /dev/null
+++ b/cfgov/wagtailadmin_overrides/templates/wagtailadmin/userbar/base.html
@@ -0,0 +1,41 @@
+{% load wagtailadmin_tags i18n %}
+
+
+ {# In preview panels, we still render the userbar UI, but hidden by default. #}
+
+
+
+
+
+
From bfc4bef91066adf09c6510febe60ec1801e2906b Mon Sep 17 00:00:00 2001
From: Wyatt Pearsall
Date: Tue, 1 Oct 2024 10:22:18 -0700
Subject: [PATCH 3/3] Added nonce example to docs
---
docs/editing-components.md | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/docs/editing-components.md b/docs/editing-components.md
index dcb9fefeb67..a0f7f483378 100644
--- a/docs/editing-components.md
+++ b/docs/editing-components.md
@@ -316,6 +316,21 @@ see [Notes on Atomic Design](atomic-structure.md).)
This will load the `related-content.js` script on any page
that includes the `RelatedContent` molecule in one of its StreamFields.
+If adding Javascript directly with a script tag is required, you'll need to add a `nonce` attribute with the value `{{request.csp_nonce}}`. This
+is due to our use of `strict-dynamic` in our Content Security Policy via [django-csp](https://django-csp.readthedocs.io/en/3.8/nonce.html).
+Here's an example from the [records-access-form template](https://github.com/cfpb/consumerfinance.gov/blob/main/cfgov/privacy/jinja2/privacy/records-access-form.html):
+
+```javascript
+{% block javascript %}
+ {{ super() }}
+
+{% endblock javascript %}
+```
+
+You'll note this uses our asynchronous javascript loaderi (jsl), which is also how js in the Media classes of components are loaded.
+
## How-to guides
### Creating a new component