Skip to content

Commit

Permalink
Merge pull request #810 from bryszard/chore/sanitize-on-actors
Browse files Browse the repository at this point in the history
Use Sanitize on actor_names
  • Loading branch information
bkeepers authored Jan 8, 2024
2 parents b27ba80 + b6dd51f commit aee29ac
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions examples/ui/basic.ru
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ Flipper::UI.configure do |config|

config.actor_names_source = lambda do |_keys|
{
'1' => 'John',
'6' => 'Brandon',
'1' => '<a href="https://johnnunemaker.com">John</a>',
'6' => '<a href="https://opensoul.org">Brandon</a>',
}
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/flipper/ui/views/feature.erb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<div class="col col-mr-auto pl-md-5">
<h6 class="m-0">
<% if Flipper::UI::Util.present?(@feature.actor_names[item]) %>
<%= "#{@feature.actor_names[item]} (#{item})" %>
<%== Sanitize.fragment("#{@feature.actor_names[item]} (#{item})", Sanitize::Config::BASIC) %>
<% else %>
<%= item %>
<% end %>
Expand Down
25 changes: 23 additions & 2 deletions spec/flipper/ui/actions/feature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,35 @@
}
}
end

get '/features/search'
end

it 'renders template with custom actor names' do
get '/features/search'
expect(last_response.body).to include('Some Actor Name (some_actor_name)')
expect(last_response.body).not_to include('Some Other Actor Name')
end

it 'allows basic html' do
Flipper::UI.configure do |config|
config.actor_names_source = lambda { |_keys|
{ "some_actor_name" => '<a href="/users/some_actor_name">Some Actor Name</a>', }
}
end

get '/features/search'
expect(last_response.body).to include('<a href="/users/some_actor_name" rel="nofollow">Some Actor Name</a>')
end

it 'sanitizes dangerous markup' do
Flipper::UI.configure do |config|
config.actor_names_source = lambda { |_keys|
{ "some_actor_name" => '<a href="javascript:alert(\'hello\')">Some Actor Name</a>', }
}
end

get '/features/search'
expect(last_response.body).not_to include('javascript:alert')
end
end
end

Expand Down

0 comments on commit aee29ac

Please sign in to comment.