From 4794db76b0f7536ce409734fe7818a8ac0ce558e Mon Sep 17 00:00:00 2001 From: Ole-Morten Duesund Date: Wed, 26 Aug 2026 12:18:47 +0200 Subject: [PATCH] Fjern inline onsubmit med innholdstekst (XSS i JS-attributt) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Jinja escaper for HTML, men nettleseren dekoder attributtverdien før JS-parseren ser den, så en tittel med ' kunne bryte ut av strengen. Bekreftelser går nå via data-confirm og én delt handler i base.html. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01JcEy43fNYpwg6K6oTKakWR --- soapbox/templates/admin/base.html | 8 ++++++++ soapbox/templates/admin/edit.html | 6 ++---- soapbox/templates/admin/users.html | 2 +- tests/test_app.py | 11 +++++++++++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/soapbox/templates/admin/base.html b/soapbox/templates/admin/base.html index 7dd3d33..cba78ab 100644 --- a/soapbox/templates/admin/base.html +++ b/soapbox/templates/admin/base.html @@ -32,5 +32,13 @@ {% endwith %} {% block content %}{% endblock %} + diff --git a/soapbox/templates/admin/edit.html b/soapbox/templates/admin/edit.html index 4e6223e..3944193 100644 --- a/soapbox/templates/admin/edit.html +++ b/soapbox/templates/admin/edit.html @@ -56,8 +56,7 @@
  • ![]({{ name }}) -
    + @@ -68,8 +67,7 @@ {% endif %} - +
    diff --git a/soapbox/templates/admin/users.html b/soapbox/templates/admin/users.html index e1c3c18..ad07771 100644 --- a/soapbox/templates/admin/users.html +++ b/soapbox/templates/admin/users.html @@ -17,7 +17,7 @@ -
    + diff --git a/tests/test_app.py b/tests/test_app.py index 03f399f..0cf9bfb 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -146,3 +146,14 @@ def test_subpath_mount(tmp_path): assert 'href="theme/style.css"' in html assert re.search(r'href="admin/"', html) assert client.get("/blog/theme/style.css").status_code == 200 + + +def test_no_inline_js_with_content(client, cfg): + """Titler med anførselstegn skal ikke havne i en JS-kontekst (XSS).""" + post_id = _create_post(client) + token = csrf(client) + title = "Ola's \"test\" " + r = client.post(f"/admin/edit/{post_id}", data={"csrf": token, "title": title, "body": "x", "action": "save"}) + html = client.get(r.headers["Location"]).text + assert "onsubmit" not in html and "onclick" not in html + assert "Ola's" in html