Skip to content

Commit e3e9e8c

Browse files
committed
Fix 32f91e4 broke fields with HTML tags
Refs. #3686 (comment), GHSA-8qgm-g2vv-vwvc
1 parent 32f91e4 commit e3e9e8c

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

.rubocop_todo.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Lint/ReturnInVoidContext:
2121
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
2222
# IgnoredMethods: refine
2323
Metrics/BlockLength:
24-
Max: 1107
24+
Max: 1119
2525

2626
# Offense count: 1
2727
# Configuration parameters: Max, CountKeywordArgs.

app/views/rails_admin/main/index.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@
133133
<% end %>
134134
<% properties.map{ |property| property.bind(:object, object) }.each do |property| %>
135135
<% value = property.pretty_value %>
136-
<td class="<%= [property.sticky? && 'sticky', property.css_class, property.type_css_class].select(&:present?).join(' ') %>" title="<%= value %>">
136+
<%= content_tag(:td, class: [property.sticky? && 'sticky', property.css_class, property.type_css_class].select(&:present?), title: strip_tags(value.to_s)) do %>
137137
<%= value %>
138-
</td>
138+
<% end %>
139139
<% end %>
140140
<td class="last links ra-sidescroll-frozen">
141141
<ul class="nav d-inline list-inline">

spec/integration/actions/index_spec.rb

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -675,16 +675,29 @@
675675
expect(find('tbody tr:nth-child(1) td:nth-child(4)')).to have_content(@players.sort_by(&:id).collect(&:name).join(', '))
676676
end
677677

678-
it 'does not allow XSS for title attribute' do
679-
RailsAdmin.config Team do
680-
list do
681-
field :name
678+
describe 'with title attribute' do
679+
it 'does not allow XSS' do
680+
RailsAdmin.config Team do
681+
list do
682+
field :name
683+
end
682684
end
685+
@team = FactoryBot.create :team, name: '" onclick="alert()" "'
686+
visit index_path(model_name: 'team')
687+
expect(find('tbody tr:nth-child(1) td:nth-child(2)')['onclick']).to be_nil
688+
expect(find('tbody tr:nth-child(1) td:nth-child(2)')['title']).to eq '" onclick="alert()" "'
689+
end
690+
691+
it 'does not break values with HTML tags' do
692+
RailsAdmin.config Player do
693+
list do
694+
field :team
695+
end
696+
end
697+
@player = FactoryBot.create :player, team: FactoryBot.create(:team)
698+
visit index_path(model_name: 'player')
699+
expect(find('tbody tr:nth-child(1) td:nth-child(2)')['title']).to eq @player.team.name
683700
end
684-
@team = FactoryBot.create :team, name: '" onclick="alert()" "'
685-
visit index_path(model_name: 'team')
686-
expect(find('tbody tr:nth-child(1) td:nth-child(2)')['onclick']).to be_nil
687-
expect(find('tbody tr:nth-child(1) td:nth-child(2)')['title']).to eq '" onclick="alert()" "'
688701
end
689702
end
690703

0 commit comments

Comments
 (0)