File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77
88module Flipper
99 module UI
10+ # Sanitize config for descriptions in list view. Removes anchor tags to
11+ # avoid nested links (the feature row is wrapped in an <a> tag).
12+ # See: https://github.com/flippercloud/flipper/issues/939
13+ SANITIZE_LIST = Sanitize ::Config . merge (
14+ Sanitize ::Config ::BASIC ,
15+ elements : Sanitize ::Config ::BASIC [ :elements ] - [ 'a' ]
16+ )
17+
1018 class Action
1119 module FeatureNameFromRoute
1220 def feature_name
Original file line number Diff line number Diff line change 4545 < div class ="text-truncate " style ="font-weight: 500 "> <%= feature . key %> </ div >
4646 <% if Flipper ::UI . configuration . show_feature_description_in_list? && Flipper ::UI ::Util . present? ( feature . description ) %>
4747 < div class ="text-muted fw-light " style ="line-height: 1.4; white-space: initial; padding: 8px 0 ">
48- <%== Sanitize . fragment ( feature . description , Sanitize :: Config :: BASIC ) %>
48+ <%== Sanitize . fragment ( feature . description , Flipper :: UI :: SANITIZE_LIST ) %>
4949 </ div >
5050 <% end %>
5151 < div class ="text-muted text-truncate ">
Original file line number Diff line number Diff line change 8888 expect ( last_response . body ) . not_to include ( '<a class="btn btn-primary btn-sm" href="/features/new">Add Feature</a>' )
8989 end
9090 end
91+
92+ context 'when descriptions have links' do
93+ before do
94+ Flipper ::UI . configuration . show_feature_description_in_list = true
95+ Flipper ::UI . configuration . descriptions_source = lambda { |_keys |
96+ { 'test_feature' => 'Check <a href="https://example.com">this link</a> for more info' }
97+ }
98+
99+ flipper [ :test_feature ] . enable
100+ end
101+
102+ it 'strips anchor tags from descriptions to avoid nested links' do
103+ get '/features'
104+
105+ expect ( last_response . status ) . to eq ( 200 )
106+ expect ( last_response . body ) . to include ( 'Check this link for more info' )
107+ expect ( last_response . body ) . not_to include ( '<a href="https://example.com">this link</a>' )
108+ end
109+ end
91110 end
92111
93112 describe 'POST /features' do
You can’t perform that action at this time.
0 commit comments