aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2018-05-27 21:33:50 +0100
committerrubenwardy <rw@rubenwardy.com>2018-05-27 21:33:50 +0100
commitca7708437b8cdb5f5719460decc83e22cac5bb68 (patch)
tree1ce808a1fb207bf8b840b7b9ab1432713b3cb4f4
parent63af1535b90358f1a26248cae217f4a74fdc1f84 (diff)
downloadcheatdb-ca7708437b8cdb5f5719460decc83e22cac5bb68.tar.xz
Fix potentiall XSS vulnerability
-rw-r--r--app/templates/packages/create_edit.html14
1 files changed, 11 insertions, 3 deletions
diff --git a/app/templates/packages/create_edit.html b/app/templates/packages/create_edit.html
index 666d4cd..8191a17 100644
--- a/app/templates/packages/create_edit.html
+++ b/app/templates/packages/create_edit.html
@@ -22,14 +22,22 @@
{% endfor %}
]
+ function escape(unsafe) {
+ return unsafe
+ .replace(/&/g, "&amp;")
+ .replace(/</g, "&lt;")
+ .replace(/>/g, "&gt;")
+ .replace(/"/g, "&quot;")
+ .replace(/'/g, "&#039;");
+ }
+
all_packages = meta_packages.slice();
{% for p in packages %}
- {# This is safe as name can only contain `[a-z0-9_]` #}
all_packages.push({
id: "{{ p.author.username }}/{{ p.name }}",
- value: {{ p.title | tojson }} + " by " + {{ p.author.display_name | tojson }},
- toString: function() { return {{ p.title | tojson }} + " by " + {{ p.author.display_name | tojson }} + " only"; },
+ value: escape({{ p.title | tojson }} + " by " + {{ p.author.display_name | tojson }}),
+ toString: function() { return escape({{ p.title | tojson }} + " by " + {{ p.author.display_name | tojson }} + " only"); },
});
{% endfor %}
</script>