You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by gc...@apache.org on 2026/09/10 19:39:02 UTC
(allura) 01/01: security fixes: turn on autoescaping for widgets, fix tracker select XSS
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch security-fixes
in repository https://gitbox.apache.org/repos/asf/allura.git
commit 18dba3cf048c9276fcfd7ba733202b5fd109b609
Author: Guillermo Cruz <gu...@slashdotmedia.com>
AuthorDate: Thu Sep 10 12:39:33 2026 -0600
security fixes: turn on autoescaping for widgets, fix tracker select XSS
---
Allura/allura/config/middleware.py | 7 +++++++
Allura/allura/lib/helpers.py | 12 ++++++------
Allura/allura/lib/widgets/auth_widgets.py | 9 ++++++++-
Allura/allura/lib/widgets/forms.py | 4 +++-
Allura/allura/tests/test_helpers.py | 5 +++++
ForgeTracker/forgetracker/widgets/ticket_form.py | 4 ++--
6 files changed, 31 insertions(+), 10 deletions(-)
diff --git a/Allura/allura/config/middleware.py b/Allura/allura/config/middleware.py
index 57a027f96..008a5338f 100644
--- a/Allura/allura/config/middleware.py
+++ b/Allura/allura/config/middleware.py
@@ -170,8 +170,15 @@ def _make_core_app(root, global_conf: dict, **app_conf):
# these are for the easywidgets' own [easy_widgets.engines] entry point
# (the Allura [easy_widgets.engines] entry point is named "jinja" (not jinja2) but it doesn't need
# any settings since it is a class that uses the same jinja env as the rest of allura)
+ # NB: this is a *second* jinja environment, separate from the one in
+ # AlluraJinjaRenderer. Widgets render through this one and their output
+ # is spliced into our own templates as Markup, so it does not inherit
+ # their autoescaping -- it has to be turned on here too. Recent
+ # easywidgets defaults it on; set it explicitly so an older pin can't
+ # silently render widgets unescaped.
**{
'jinja2.auto_reload': asbool(config['auto_reload_templates']),
+ 'jinja2.autoescape': True,
'jinja2.bytecode_cache': AlluraJinjaRenderer._setup_bytecode_cache(),
'jinja2.cache_size': asint(config.get('jinja_cache_size', -1)),
}
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index d51057b7f..21c256ec1 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -1029,12 +1029,12 @@ def split_select_field_options(field_options):
field_options = shlex_split(field_options)
except ValueError:
field_options = field_options.split()
- # After regular split field_options might contain a " characters,
- # which would break html when rendered inside tag's value attr.
- # Escaping doesn't help here, 'cause it breaks EasyWidgets' validation,
- # so we're getting rid of those.
- field_options = [o.replace('"', '') for o in field_options]
- return field_options
+ # An option containing a " breaks out of the value attr it gets rendered
+ # into. shlex_split can hand one through even on the success path -- it
+ # unescapes \" inside a quoted word -- so strip them on *both* branches,
+ # not just after the plain split. Escaping instead of stripping isn't an
+ # option here, it breaks EasyWidgets' validation of the submitted value.
+ return [o.replace('"', '') for o in field_options]
@contextmanager
diff --git a/Allura/allura/lib/widgets/auth_widgets.py b/Allura/allura/lib/widgets/auth_widgets.py
index 1382545cb..38efc5df5 100644
--- a/Allura/allura/lib/widgets/auth_widgets.py
+++ b/Allura/allura/lib/widgets/auth_widgets.py
@@ -29,6 +29,13 @@
from allura.lib import plugin
+# Emits already-rendered markup as-is. The antispam honeypot fields arrive as
+# Markup, so passing them as *template source* is both pointless and risky --
+# a '$' in the content would be read as a core-ew substitution. Render them as
+# data instead.
+_raw_html = ew.Snippet('{{widget.text|safe}}', 'jinja2')
+
+
class LoginForm(ForgeForm):
submit_text = 'Login'
style = 'wide'
@@ -62,7 +69,7 @@ def fields(self):
for fld in g.antispam.extra_fields():
fields.append(
- ew_core.Widget(template=ew.Snippet(fld)))
+ ew_core.Widget(template=_raw_html, text=fld))
return fields
diff --git a/Allura/allura/lib/widgets/forms.py b/Allura/allura/lib/widgets/forms.py
index cb48c535e..de6eba00f 100644
--- a/Allura/allura/lib/widgets/forms.py
+++ b/Allura/allura/lib/widgets/forms.py
@@ -44,9 +44,11 @@
class _HTMLExplanation(ew.InputField):
+ # text is developer-supplied markup (never user input); |safe keeps
+ # easywidgets' autoescaping from mangling it
template = ew.Snippet(
'''<label class="grid-4"> </label>
- <div class="grid-14" style="margin:2px;">{{widget.text}}</div>
+ <div class="grid-14" style="margin:2px;">{{widget.text|safe}}</div>
''',
'jinja2')
diff --git a/Allura/allura/tests/test_helpers.py b/Allura/allura/tests/test_helpers.py
index 5ea729e59..57da40663 100644
--- a/Allura/allura/tests/test_helpers.py
+++ b/Allura/allura/tests/test_helpers.py
@@ -413,6 +413,11 @@ def test_split_select_field_options():
['test', 'message', 'test2'])
assert (h.split_select_field_options('abc ƒå∂ ººº') ==
['abc', 'ƒå∂', 'ººº'])
+ # shlex unescapes \" inside a quoted word, so a double quote can reach the
+ # option even when parsing succeeds. It has to be stripped there too, or
+ # it breaks out of the value attr the option is rendered into.
+ assert (h.split_select_field_options(r'"x\" onmouseover=alert(1) y" normal') ==
+ ['x onmouseover=alert(1) y', 'normal'])
def test_notifications_disabled():
diff --git a/ForgeTracker/forgetracker/widgets/ticket_form.py b/ForgeTracker/forgetracker/widgets/ticket_form.py
index b53bfdafc..6a3e59368 100644
--- a/ForgeTracker/forgetracker/widgets/ticket_form.py
+++ b/ForgeTracker/forgetracker/widgets/ticket_form.py
@@ -240,12 +240,12 @@ class MilestoneField(ew.SingleSelectField):
'class':css_class},
attrs)}}>
{% for o in open_milestones %}
- <option{% if o.selected%} selected{% endif %} value="{{o.html_value}}">{{o.label|e}}</option>
+ <option{% if o.selected%} selected{% endif %} value="{{o.html_value|e}}">{{o.label|e}}</option>
{% endfor %}
{% if closed_milestones %}
<optgroup label="Closed">
{% for o in closed_milestones %}
- <option{% if o.selected%} selected{% endif %} value="{{o.html_value}}">{{o.label|e}}</option>
+ <option{% if o.selected%} selected{% endif %} value="{{o.html_value|e}}">{{o.label|e}}</option>
{% endfor %}
</optgroup>
{% endif %}