Skip to content

Commit 596117d

Browse files
Copilotwhomingbird
andauthored
Fix XSS vulnerabilities in extended metadata helpers, samples helper, and views
Agent-Logs-Url: https://github.com/seek4science/seek/sessions/a0db5e17-9a4c-4ea4-b006-fc781a2ff034 Co-authored-by: whomingbird <42063448+whomingbird@users.noreply.github.com>
1 parent fdd2e0c commit 596117d

6 files changed

Lines changed: 20 additions & 20 deletions

File tree

app/helpers/bootstrap_helper.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def button_link_to(text, icon, url, options = {})
2929

3030
# A collapsible panel
3131
def folding_panel(title = nil, collapsed = false, options = {}, &block)
32+
title = h(title) unless title.nil? || title.html_safe?
3233
title += " <span class=\"#{collapsed ? 'caret' : 'caret-up'}\"></span>".html_safe
3334

3435
options[:collapsible] = true
@@ -70,12 +71,12 @@ def panel(title = nil, options = {}, &block)
7071

7172
def panel_title(title, options, heading_options)
7273
content_tag(:div, heading_options) do # The panel title
73-
title_html = ''
74+
title_html = ''.html_safe
7475
if (help_text = options.delete(:help_text))
75-
title_html << "#{help_icon(help_text)} "
76+
title_html << "#{help_icon(help_text)} ".html_safe
7677
end
7778
title_html << title
78-
title_html.html_safe
79+
title_html
7980
end
8081
end
8182

app/helpers/extended_metadata_helper.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def extended_metadata_form_field_for_attribute(attribute, resource, parent_resou
1212

1313
if attribute.linked_extended_metadata? || attribute.linked_extended_metadata_multi?
1414
content_tag(:span, class: 'linked_extended_metdata') do
15-
folding_panel(attribute.label, false, id:attribute.title) do
15+
folding_panel(h(attribute.label), false, id:attribute.title) do
1616
attribute_form_element(attribute, resource.extended_metadata.get_attribute_value(attribute.title), element_name, element_class)
1717
end
1818
end
@@ -23,10 +23,9 @@ def extended_metadata_form_field_for_attribute(attribute, resource, parent_resou
2323
end
2424

2525
def extended_metadata_attribute_description(description)
26-
html = '<p class="help-block">'
27-
html += '<small>'+description+'</small>'
28-
html += '</p>'
29-
html.html_safe
26+
content_tag(:p, class: 'help-block') do
27+
content_tag(:small, description)
28+
end
3029
end
3130

3231
def render_extended_metadata_value(attribute, resource)
@@ -38,7 +37,7 @@ def render_extended_metadata_value(attribute, resource)
3837
content_tag(:div, class: 'extended_metadata') do
3938
if attribute.linked_extended_metadata? || attribute.linked_extended_metadata_multi?
4039
content_tag(:span, class: 'linked_extended_metdata_display') do
41-
folding_panel(attribute.label, false, id: attribute.title) do
40+
folding_panel(h(attribute.label), false, id: attribute.title) do
4241
display_attribute(resource.extended_metadata, attribute, link: true)
4342
end
4443
end

app/helpers/samples_helper.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def linked_extended_metadata_form_field(attribute, value, element_name, element_
5151

5252
attribute.linked_extended_metadata_type.extended_metadata_attributes.each do |attr|
5353
attr_element_name = "#{element_name}[#{attr.title}]"
54-
html += '<div class="form-group"><label>'+attr.label+'</label>'
54+
html += '<div class="form-group"><label>'+h(attr.label)+'</label>'
5555
html += required_span if attr.required?
5656
v = value ? value[attr.title] : nil
5757
if attr.linked_extended_metadata?
@@ -104,16 +104,16 @@ def authorised_samples(projects = nil)
104104
end
105105

106106
def sample_attribute_display_title(attribute)
107-
title = attribute.title
107+
title = h(attribute.title)
108108
if (unit = attribute.unit) && !unit.dimensionless?
109-
title += " ( #{unit} )"
109+
title += h(" ( #{unit} )")
110110
end
111111
unless attribute.pid.blank?
112112
title += content_tag(:small, 'data-tooltip'=>attribute.pid) do
113-
" [ "+attribute.short_pid+ " ]"
114-
end.html_safe
113+
(" [ "+h(attribute.short_pid)+ " ]").html_safe
114+
end
115115
end
116-
title.html_safe
116+
title
117117
end
118118

119119
def display_attribute(resource, attribute, options = {})
@@ -194,12 +194,12 @@ def linked_extended_metadata_attribute_display(value, attribute)
194194
html += '<li>'
195195
if attr.linked_extended_metadata? || attr.linked_extended_metadata_multi?
196196
html += content_tag(:span, class: 'linked_extended_metdata_display') do
197-
folding_panel(attr.label, true, id:attr.title) do
197+
folding_panel(h(attr.label), true, id:attr.title) do
198198
display_attribute_value(v, attr)
199199
end
200200
end
201201
else
202-
html += '<label>'+attr.title+'</label>'+' : '
202+
html += '<label>'+h(attr.title)+'</label>'+' : '
203203
html += display_attribute_value(v, attr)
204204
end
205205
html += '</li>'

app/views/samples/_sample_error_messages.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<p>There were problems with the following fields:</p>
55
<ul>
66
<% object.errors.each do |error| %>
7-
<li><%= error.full_message.html_safe %></li>
7+
<li><%= error.full_message %></li>
88
<% end %>
99
</ul>
1010
</div>

app/views/samples/_table_view.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<%# Wrapping <div> needed for popover to display properly %>
5050
<%= content_tag(:div, data: {
5151
toggle: 'popover',
52-
content: errors.map { |e| "#{attribute.title} #{e}<br/>" }.join.html_safe }) do %>
52+
content: errors.map { |e| "#{h(attribute.title)} #{e}<br/>" }.join.html_safe }) do %>
5353
<%= text_or_not_specified(sample.get_attribute_value(attribute), auto_link: link) %>
5454
<% end %>
5555
</td>

app/views/spreadsheets/_spreadsheet_errors.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<h1><%= errors.size > 1 ? "Errors" : "An error"-%> occurred whilst <%= verb -%> your annotation</h1>
33
<ul>
44
<% errors.each do |error| %>
5-
<li><%= error.full_message.html_safe %></li>
5+
<li><%= error.full_message %></li>
66
<% end %>
77
</ul>
88
</div>

0 commit comments

Comments
 (0)