Skip to content

Commit

Permalink
Fix XSS vulnerability in the list view
Browse files Browse the repository at this point in the history
  • Loading branch information
mshibuya committed Jul 6, 2024
1 parent e066c4f commit d84b398
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/views/rails_admin/main/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
%td.other.left= link_to "...", @other_left_link, class: 'pjax'
- properties.map{ |property| property.bind(:object, object) }.each do |property|
- value = property.pretty_value
%td{class: "#{property.css_class} #{property.type_css_class}", title: strip_tags(value.to_s)}= value
%td{class: "#{property.css_class} #{property.type_css_class}", title: value}= value
- if @other_right_link ||= other_right && index_path(params.merge(set: (params[:set].to_i + 1)))
%td.other.right= link_to "...", @other_right_link, class: 'pjax'
- unless frozen_columns
Expand Down
12 changes: 12 additions & 0 deletions spec/integration/actions/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,18 @@
visit index_path(model_name: 'team')
expect(find('tbody tr:nth-child(1) td:nth-child(4)')).to have_content(@players.sort_by(&:id).collect(&:name).join(', '))
end

it 'does not allow XSS for title attribute' do
RailsAdmin.config Team do
list do
field :name
end
end
@team = FactoryBot.create :team, name: '" onclick="alert()" "'
visit index_path(model_name: 'team')
expect(find('tbody tr:nth-child(1) td:nth-child(2)')['onclick']).to be_nil
expect(find('tbody tr:nth-child(1) td:nth-child(2)')['title']).to eq '" onclick="alert()" "'
end
end

context 'without pagination' do
Expand Down

0 comments on commit d84b398

Please sign in to comment.