Fix potentiall XSS vulnerability

This commit is contained in:
rubenwardy 2018-05-27 21:33:50 +01:00
parent 63af1535b9
commit ca7708437b
No known key found for this signature in database
GPG Key ID: A1E29D52FF81513C
1 changed files with 11 additions and 3 deletions

View File

@ -22,14 +22,22 @@
{% endfor %}
]
function escape(unsafe) {
return unsafe
.replace(/&/g, "&")
.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>