From c6cce54d5f2496b686a7102306c9e8c08859a078 Mon Sep 17 00:00:00 2001 From: John Thiltges Date: Thu, 3 Jan 2019 13:12:53 -0600 Subject: [PATCH] Escape form values with markupsafe - Use markupsafe to format escaped HTML fragments - Correct the formatting problems introduced with the XSS fixes --- resources/templates/form.tmpl | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/resources/templates/form.tmpl b/resources/templates/form.tmpl index c984641..243b173 100644 --- a/resources/templates/form.tmpl +++ b/resources/templates/form.tmpl @@ -1,5 +1,6 @@ ## -*- coding: utf-8 -*- <% +from markupsafe import Markup len_attr = len(attributes) switch = len_attr / 2 if not switch * 2 == len_attr: @@ -31,32 +32,32 @@ for a in sorted(attributes.keys(), key=lambda attr: attributes[attr]['weight']): raw_value = values[a] if raw_value is None: raw_value = '' - value = ' value="'+ raw_value + '"' - value2 = '' + value = Markup(' value="{}"').format(raw_value) + value2 = Markup('').format(raw_value) else: raw_value = '' value = '' value2 = '' if 'default' in attr and value == '': - value = ' value="'+ attr['default'] + '"' + value = Markup(' value="{}"').format(attr['default']) %> ${attr['display_name']} % if modify and a == keyattr: - + ${raw_value} % elif attr['type'] == 'string': - + % elif attr['type'] == 'email': - + % elif attr['type'] == 'int': - + % elif attr['type'] == 'fix': ${attr['value']} % elif attr['type'] == 'stringlist':