From b2ef6ca25cc14d572021d9178880dab8b6f98aaa Mon Sep 17 00:00:00 2001 From: Jesse Vickery Date: Wed, 13 Aug 2025 16:26:23 +0000 Subject: [PATCH 01/12] feat(dev): asset nonce; - Add support for CSP Nonces for strict-dynamic directive. --- ckan/lib/webassets_tools.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ckan/lib/webassets_tools.py b/ckan/lib/webassets_tools.py index 3fe27218541..b841d5cbfbe 100644 --- a/ckan/lib/webassets_tools.py +++ b/ckan/lib/webassets_tools.py @@ -11,7 +11,8 @@ from webassets import Environment from webassets.loaders import YAMLLoader -from ckan.common import config, g +# (canada fork only): use CSP nonce to support strict-dynamic +from ckan.common import config, g, request logger = logging.getLogger(__name__) @@ -128,9 +129,13 @@ def include_asset(name: str) -> None: def _to_tag(url: str, type_: str): if type_ == u'style': - return u''.format(url) + # (canada fork only): use CSP nonce to support strict-dynamic + return u''.format( + url, str(request.environ.get('CSP_NONCE', ''))) elif type_ == u'script': - return u''.format(url) + # (canada fork only): use CSP nonce to support strict-dynamic + return u''.format( + url, str(request.environ.get('CSP_NONCE', ''))) return u'' From 3b375eba86395b58f6aebb3846dad85c22a6b049 Mon Sep 17 00:00:00 2001 From: Jesse Vickery Date: Wed, 13 Aug 2025 16:32:24 +0000 Subject: [PATCH 02/12] feat(misc): changelog; - Added change log file. --- changes/204.canada.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/204.canada.feature diff --git a/changes/204.canada.feature b/changes/204.canada.feature new file mode 100644 index 00000000000..fefffbacd51 --- /dev/null +++ b/changes/204.canada.feature @@ -0,0 +1 @@ +Adds script/style nonce capabilities to Jinja2 webassets. \ No newline at end of file From 3dcd22845f2bf03ea65b4d0c5f6b4a7e1031553a Mon Sep 17 00:00:00 2001 From: Jesse Vickery Date: Tue, 19 Aug 2025 14:26:04 +0000 Subject: [PATCH 03/12] fix(templates): inline eval; - Continued unsafe inline stuffs. --- ckanext/datatablesview/public/datatablesview.js | 11 +++++++++++ .../templates/datatables/datatables_form.html | 3 ++- .../templates/datatables/datatables_view.html | 9 ++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/ckanext/datatablesview/public/datatablesview.js b/ckanext/datatablesview/public/datatablesview.js index 1daa4bf93d1..e7fe376e48c 100644 --- a/ckanext/datatablesview/public/datatablesview.js +++ b/ckanext/datatablesview/public/datatablesview.js @@ -421,6 +421,7 @@ this.ckan.module('datatables_view', function (jQuery) { display: $.fn.dataTable.Responsive.display.modal({ header: function (row) { // add clipboard and print buttons to modal record display + // TODO: move style attributes to classes... var data = row.data(); return 'Details:  
' + ' + {# (canada forn only): no inline event handler for CSP support #} + {% for field in datadictionary -%} {% if 'show_fields' not in resource_view or field.id in resource_view.show_fields -%} @@ -103,7 +105,8 @@ {#- we create tooltip here instead of javascript so we can leverage the automatic-local-datetime class date conversion CKAN does -#} {%- set res = resource %} -