mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-11-22 00:21:50 +01:00
fix(templates): pass names to hyperscript through data attributes
Django's ' escaping is decoded by the browser before hyperscript parses a _="..." attribute, so a quote in a currency or account name closed the string and the rest ran as hyperscript. Names now live in plain data-* attributes and are read with @data-*. Spaces in currency prefixes and suffixes are kept. Refs GHSA-fh52-f8r4-hv6g
This commit is contained in:
1 parent
2997cf72f0
commit
c8f972d01a
3 files changed
+17
-9
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import re
|
||||
import tempfile
|
||||
from datetime import date
|
||||
from decimal import Decimal
|
||||
@@ -71,7 +72,7 @@ class NetWorthCurrencyChartTests(TestCase):
|
||||
self.assertEqual(consolidated["pointHitRadius"], 8)
|
||||
self.assertContains(
|
||||
response,
|
||||
"showOnlyCurrencyDataset('US Dollar Consolidated', 'US Dollar')",
|
||||
'data-dataset="US Dollar Consolidated" data-difference="US Dollar"',
|
||||
html=False,
|
||||
)
|
||||
self.assertContains(
|
||||
@@ -156,3 +157,8 @@ class NetWorthChartEscapingTests(TestCase):
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertNotContains(response, "<script>alert(1)")
|
||||
# Entities in an attribute are decoded before hyperscript parses it, so
|
||||
# names must never be interpolated into ``_="..."`` code.
|
||||
hyperscript = re.findall(r'\s_="([^"]*)"', response.content.decode())
|
||||
self.assertTrue(hyperscript)
|
||||
self.assertFalse([code for code in hyperscript if "alert(1)" in code])
|
||||
@@ -78,10 +78,12 @@
|
||||
<div class="fieldset">
|
||||
<span class="fieldset-legend">{% translate 'Difference' %}</span>
|
||||
<div class="text-base"
|
||||
data-prefix="{{ form.currency_prefix }}"
|
||||
data-suffix="{{ form.currency_suffix }}"
|
||||
_="on input from #id_form-{{ forloop.counter0 }}-new_balance
|
||||
set original_amount to parseFloat('{{ form.current_balance|floatformat:"-40u" }}')
|
||||
then set prefix to '{{ form.currency_prefix }}'
|
||||
then set suffix to '{{ form.currency_suffix }}'
|
||||
then set prefix to @data-prefix
|
||||
then set suffix to @data-suffix
|
||||
then set decimal_places to {{ form.currency_decimal_places }}
|
||||
then call parseLocaleNumber(#id_form-{{ forloop.counter0 }}-new_balance.value)
|
||||
then set new_amount to result
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
<li>
|
||||
{% if currency.consolidated and currency.consolidated.total_final != currency.total_final %}
|
||||
<a class="cursor-pointer select-auto flex justify-between items-center w-full"
|
||||
_="on click showOnlyCurrencyDataset('{{ currency.currency.name }}', '{{ currency.currency.name }}')">
|
||||
data-dataset="{{ currency.currency.name }}" data-difference="{{ currency.currency.name }}" _="on click showOnlyCurrencyDataset(@data-dataset, @data-difference)">
|
||||
<span
|
||||
class="currency-name text-start font-mono shrink text-ellipsis">{{ currency.currency.name }}</span>
|
||||
<span class="text-end shrink-0">
|
||||
@@ -86,7 +86,7 @@
|
||||
else call localStorage.setItem('net-worth-consolidated-{{ currency.currency.id }}', 'closed') end
|
||||
catch e log e end">
|
||||
<summary class="cursor-pointer text-base-content/60 select-auto flex"
|
||||
_="on click showOnlyCurrencyDataset('{{ currency.currency.name }} {% trans "Consolidated" %}', '{{ currency.currency.name }}')">
|
||||
data-dataset="{{ currency.currency.name }} {% trans "Consolidated" %}" data-difference="{{ currency.currency.name }}" _="on click showOnlyCurrencyDataset(@data-dataset, @data-difference)">
|
||||
<span class="flex justify-between items-center w-full">
|
||||
<span class="text-start shrink">{% trans "Consolidated" %}</span>
|
||||
<span class="text-end shrink-0">
|
||||
@@ -104,7 +104,7 @@
|
||||
{% for component in currency.consolidated.components %}
|
||||
<li class="col-span-3 grid grid-cols-subgrid">
|
||||
<a class="col-span-3 grid grid-cols-subgrid items-center cursor-pointer text-base-content/60 select-auto text-sm"
|
||||
_="on click showOnlyCurrencyDataset('{{ component.currency.name }}', '{{ component.currency.name }}')">
|
||||
data-dataset="{{ component.currency.name }}" data-difference="{{ component.currency.name }}" _="on click showOnlyCurrencyDataset(@data-dataset, @data-difference)">
|
||||
<span class="currency-name text-start font-mono truncate">{{ component.currency.name }}</span>
|
||||
<span class="justify-self-start">
|
||||
{% if component.share is not None %}
|
||||
@@ -128,7 +128,7 @@
|
||||
</ul>
|
||||
{% else %}
|
||||
<a class="cursor-pointer select-auto flex justify-between items-center w-full"
|
||||
_="on click showOnlyCurrencyDataset('{{ currency.currency.name }}', '{{ currency.currency.name }}')">
|
||||
data-dataset="{{ currency.currency.name }}" data-difference="{{ currency.currency.name }}" _="on click showOnlyCurrencyDataset(@data-dataset, @data-difference)">
|
||||
<span class="currency-name text-start font-mono shrink">{{ currency.currency.name }}</span>
|
||||
<span class="text-end shrink-0">
|
||||
<div>
|
||||
@@ -207,7 +207,7 @@
|
||||
{% for account in data.list %}
|
||||
<li>
|
||||
<a class="cursor-pointer select-auto flex justify-between items-center w-full"
|
||||
_="on click showOnlyAccountDataset('{{ account.account.name }}')">
|
||||
data-dataset="{{ account.account.name }}" _="on click showOnlyAccountDataset(@data-dataset)">
|
||||
<span
|
||||
class="account-name text-start font-mono shrink text-ellipsis">{{ account.account.name }}</span>
|
||||
<span class="text-end shrink-0">
|
||||
@@ -237,7 +237,7 @@
|
||||
{% for account in data.list %}
|
||||
<li>
|
||||
<a class="cursor-pointer flex select-auto justify-between items-center w-full"
|
||||
_="on click showOnlyAccountDataset('{{ account.account.name }}')">
|
||||
data-dataset="{{ account.account.name }}" _="on click showOnlyAccountDataset(@data-dataset)">
|
||||
<span class="account-name text-start font-mono shrink">{{ account.account.name }}</span>
|
||||
<span class="text-end shrink-0">
|
||||
<div>
|
||||
|
||||
Reference in new issue
Block a user