]> source.dussan.org Git - redmine.git/commitdiff
Fix that inline issue auto complete does not sanitize HTML tags (#33846).
authorGo MAEDA <maeda@farend.jp>
Fri, 19 Mar 2021 04:24:31 +0000 (04:24 +0000)
committerGo MAEDA <maeda@farend.jp>
Fri, 19 Mar 2021 04:24:31 +0000 (04:24 +0000)
Patch by Marius BALTEANU.

git-svn-id: http://svn.redmine.org/redmine/trunk@20827 e93f8b46-1217-0410-a6f0-8f06a7374b81

public/javascripts/application.js
test/system/inline_autocomplete_test.rb

index aa0c9ed0bd07053629fdf0b8eb9132afd7bae2bd..0467d97db8600c564ba12c8276252d52fd286418 100644 (file)
@@ -1,6 +1,12 @@
 /* Redmine - project management software
    Copyright (C) 2006-2020  Jean-Philippe Lang */
 
+function sanitizeHTML(string) {
+  var temp = document.createElement('span');
+  temp.textContent = string;
+  return temp.innerHTML;
+}
+
 function checkAll(id, checked) {
   $('#'+id).find('input[type=checkbox]:enabled').prop('checked', checked);
 }
@@ -1161,6 +1167,9 @@ function inlineAutoComplete(element) {
           selectTemplate: function (issue) {
             return '#' + issue.original.id;
           },
+          menuItemTemplate: function (issue) {
+            return sanitizeHTML(issue.original.label);
+          },
           noMatchTemplate: function () {
             return '<span style:"visibility: hidden;"></span>';
           }
index f3c7daef6ba1901478540cba1df37cc10a21f233..b2f943d05d8cd9d9d8f6236a0bc498bf0637f0ad 100644 (file)
@@ -151,4 +151,17 @@ class InlineAutocompleteSystemTest < ApplicationSystemTestCase
     end
     assert_equal '[[Page_with_sections]] ', find('#issue_description').value
   end
+
+  def test_inline_autocomplete_for_issues_should_escape_html_elements
+    issue = Issue.generate!(subject: 'This issue has a <select> element', project_id: 1, tracker_id: 1)
+
+    log_user('jsmith', 'jsmith')
+    visit 'projects/1/issues/new'
+
+    fill_in 'Description', :with => '#This'
+
+    within('.tribute-container') do
+      assert page.has_text? "Bug ##{issue.id}: This issue has a <select> element"
+    end
+  end
 end