Browse Source

Introduces escaping in Horizon/Orchestration

1) Escape help_text a second time to avoid bootstrap tooltip XSS issue

The "Description" parameter in a Heat template is used to populate
a help_text tooltip in the dynamically generated Heat form. Bootstrap
inserts this tooltip into the DOM using .html() which undoes any
escaping we do in Django (it should be using .text()).

This was fixed by forcing the help_text content to be escaped a second
time. The issue itself is mitigated in bootstrap.js release 2.0.3
(ours is currently 2.0.1).

2) Properly escape untrusted Heat template 'outputs'

The 'outputs' parameter in a Heat template was included in a Django
template with HTML autoescaping turned off. Malicious HTML content
could be included in a Heat template and would be rendered by Horizon
when details about a created stack were displayed.

This was fixed by not disabling autoescaping and explicitly escaping
untrusted values in any strings that are later marked "safe" to render
without further escaping.

Change-Id: Icd9f9d9ca77068b12227d77469773a325c840001
Closes-Bug: #1289033
Co-Authored-By: Kieran Spear <kispear@gmail.com>
CristianFiorentino 5 years ago
parent
commit
1b0106e280

+ 6
- 1
horizon/templates/horizon/common/_form_fields.html View File

@@ -19,7 +19,12 @@
19 19
         <span class="help-inline">{{ error }}</span>
20 20
       {% endfor %}
21 21
     {% endif %}
22
-    <span class="help-block">{{ field.help_text }}</span>
22
+    {% comment %}
23
+    Escape help_text a second time here, to avoid an XSS issue in bootstrap.js.
24
+    This can most likely be removed once we upgrade bootstrap.js past 2.0.2.
25
+    Note: the spaces are necessary here.
26
+    {% endcomment %}
27
+    <span class="help-block">{% filter force_escape %} {{ field.help_text }} {% endfilter %} </span>
23 28
     <div class="input">
24 29
       {{ field }}
25 30
     </div>

+ 8
- 2
openstack_dashboard/dashboards/project/stacks/mappings.py View File

@@ -18,6 +18,8 @@ import re
18 18
 
19 19
 from django.core.urlresolvers import reverse
20 20
 from django.template.defaultfilters import register  # noqa
21
+from django.utils import html
22
+from django.utils import safestring
21 23
 import six.moves.urllib.parse as urlparse
22 24
 
23 25
 from openstack_dashboard.api import swift
@@ -76,11 +78,15 @@ def stack_output(output):
76 78
     if not output:
77 79
         return u''
78 80
     if isinstance(output, dict) or isinstance(output, list):
79
-        return u'<pre>%s</pre>' % json.dumps(output, indent=2)
81
+        json_string = json.dumps(output, indent=2)
82
+        safe_output = u'<pre>%s</pre>' % html.escape(json_string)
83
+        return safestring.mark_safe(safe_output)
80 84
     if isinstance(output, basestring):
81 85
         parts = urlparse.urlsplit(output)
82 86
         if parts.netloc and parts.scheme in ('http', 'https'):
83
-            return u'<a href="%s" target="_blank">%s</a>' % (output, output)
87
+            url = html.escape(output)
88
+            safe_link = u'<a href="%s" target="_blank">%s</a>' % (url, url)
89
+            return safestring.mark_safe(safe_link)
84 90
     return unicode(output)
85 91
 
86 92
 

+ 1
- 2
openstack_dashboard/dashboards/project/stacks/templates/stacks/_detail_overview.html View File

@@ -36,9 +36,8 @@
36 36
     <dt>{{ output.output_key }}</dt>
37 37
     <dd>{{ output.description }}</dd>
38 38
     <dd>
39
-    {% autoescape off %}
40 39
     {{ output.output_value|stack_output }}
41
-    {% endautoescape %}</dd>
40
+    </dd>
42 41
     {% endfor %}
43 42
   </dl>
44 43
 </div>

+ 11
- 6
openstack_dashboard/dashboards/project/stacks/tests.py View File

@@ -17,6 +17,7 @@ import json
17 17
 from django.core import exceptions
18 18
 from django.core.urlresolvers import reverse
19 19
 from django import http
20
+from django.utils import html
20 21
 
21 22
 from mox import IsA  # noqa
22 23
 
@@ -78,12 +79,16 @@ class MappingsTests(test.TestCase):
78 79
         self.assertEqual(u'foo', mappings.stack_output('foo'))
79 80
         self.assertEqual(u'', mappings.stack_output(None))
80 81
 
81
-        self.assertEqual(
82
-            u'<pre>[\n  "one", \n  "two", \n  "three"\n]</pre>',
83
-            mappings.stack_output(['one', 'two', 'three']))
84
-        self.assertEqual(
85
-            u'<pre>{\n  "foo": "bar"\n}</pre>',
86
-            mappings.stack_output({'foo': 'bar'}))
82
+        outputs = ['one', 'two', 'three']
83
+        expected_text = """[\n  "one", \n  "two", \n  "three"\n]"""
84
+
85
+        self.assertEqual(u'<pre>%s</pre>' % html.escape(expected_text),
86
+                         mappings.stack_output(outputs))
87
+
88
+        outputs = {'foo': 'bar'}
89
+        expected_text = """{\n  "foo": "bar"\n}"""
90
+        self.assertEqual(u'<pre>%s</pre>' % html.escape(expected_text),
91
+                         mappings.stack_output(outputs))
87 92
 
88 93
         self.assertEqual(
89 94
             u'<a href="http://www.example.com/foo" target="_blank">'

Loading…
Cancel
Save