diff --git a/src/secfoo/web/static/js/interactive.js b/src/secfoo/web/static/js/interactive.js index ceb7e8d..e223c15 100644 --- a/src/secfoo/web/static/js/interactive.js +++ b/src/secfoo/web/static/js/interactive.js @@ -22,6 +22,17 @@ // -- a normal form-submit button that just asks for confirmation // first; cancelling prevents the submit (replaces the old // onclick="return confirm(...)" pattern, also CSP-blocked). +// +// -- submits its enclosing form as soon as the selection changes +// (replaces the old onchange="this.form.submit()" filter dropdowns, +// which the CSP blocked the same way). +document.addEventListener("change", function (event) { + const field = event.target.closest("[data-autosubmit]"); + if (field && field.form) { + field.form.submit(); + } +}); + document.addEventListener("click", function (event) { const deleteButton = event.target.closest("[data-delete-url]"); if (deleteButton) { diff --git a/src/secfoo/web/templates/activities/detail.html b/src/secfoo/web/templates/activities/detail.html index fc0b5e9..5ec2450 100644 --- a/src/secfoo/web/templates/activities/detail.html +++ b/src/secfoo/web/templates/activities/detail.html @@ -102,7 +102,7 @@

Architecture diagram

{% if diagram_projects | length > 1 %}
- {% for p in diagram_projects %} {% endfor %} diff --git a/src/secfoo/web/templates/activities/sast_findings_list.html b/src/secfoo/web/templates/activities/sast_findings_list.html index 71df4f3..8388f76 100644 --- a/src/secfoo/web/templates/activities/sast_findings_list.html +++ b/src/secfoo/web/templates/activities/sast_findings_list.html @@ -12,7 +12,7 @@

All findings

- {% for p in projects %} diff --git a/src/secfoo/web/templates/activities/sca_vulnerabilities_list.html b/src/secfoo/web/templates/activities/sca_vulnerabilities_list.html index e496ff0..cd64f93 100644 --- a/src/secfoo/web/templates/activities/sca_vulnerabilities_list.html +++ b/src/secfoo/web/templates/activities/sca_vulnerabilities_list.html @@ -7,7 +7,7 @@

All vulnerabilities

- {% for p in projects %} diff --git a/src/secfoo/web/templates/activities/secret_scanning_findings_list.html b/src/secfoo/web/templates/activities/secret_scanning_findings_list.html index 2138671..6630089 100644 --- a/src/secfoo/web/templates/activities/secret_scanning_findings_list.html +++ b/src/secfoo/web/templates/activities/secret_scanning_findings_list.html @@ -7,7 +7,7 @@

All findings

- {% for p in projects %} diff --git a/src/secfoo/web/templates/assessments/list.html b/src/secfoo/web/templates/assessments/list.html index fc313ac..770b55d 100644 --- a/src/secfoo/web/templates/assessments/list.html +++ b/src/secfoo/web/templates/assessments/list.html @@ -18,7 +18,7 @@

Assessment register

- diff --git a/tests/test_web/test_no_inline_scripts.py b/tests/test_web/test_no_inline_scripts.py index 3042b80..b056236 100644 --- a/tests/test_web/test_no_inline_scripts.py +++ b/tests/test_web/test_no_inline_scripts.py @@ -21,7 +21,9 @@ Path(__file__).parents[2] / "portal" / "templates", ] -_ONCLICK_RE = re.compile(r"\bonclick\s*=") +# Any inline event-handler attribute inside a tag (onclick, onchange, +# onsubmit, oninput, ...) -- the CSP blocks all of them, not just onclick. +_INLINE_HANDLER_RE = re.compile(r"<[^>]*\son[a-z]+\s*=", re.IGNORECASE) _INLINE_SCRIPT_RE = re.compile(r"]*\bsrc=)[^>]*>") @@ -29,17 +31,18 @@ def _all_templates() -> list[Path]: return [f for d in TEMPLATE_DIRS for f in d.rglob("*.html")] -def test_no_template_uses_an_inline_onclick_attribute(): +def test_no_template_uses_an_inline_event_handler_attribute(): offenders = { str(f): m.group(0) for f in _all_templates() - for m in [_ONCLICK_RE.search(f.read_text())] + for m in [_INLINE_HANDLER_RE.search(f.read_text())] if m } assert not offenders, ( - f"Found onclick=... attributes, CSP-blocked on the portal: {offenders}. " - "Use data-href (row navigation) or data-confirm/data-delete-url " - "(confirm dialogs, delete buttons) with static/js/interactive.js instead." + f"Found inline on...= event handlers, CSP-blocked on the portal: {offenders}. " + "Use data-href (row navigation), data-confirm/data-delete-url " + "(confirm dialogs, delete buttons) or data-autosubmit (filter dropdowns) " + "with static/js/interactive.js instead." )