diff --git a/app/helpers/format_helper.rb b/app/helpers/format_helper.rb index 26014f89..152ac239 100644 --- a/app/helpers/format_helper.rb +++ b/app/helpers/format_helper.rb @@ -202,7 +202,7 @@ module FormatHelper safe_links_only: true } markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(render_options), markdown_options) - sanitize(markdown.render(text)) + sanitize(sanitize(markdown.render(text)), scrubber: Loofah::Scrubbers::NoFollow.new) end def markdown_hint(text='') diff --git a/spec/helpers/format_helper_spec.rb b/spec/helpers/format_helper_spec.rb index 4e64eb94..e4190d09 100644 --- a/spec/helpers/format_helper_spec.rb +++ b/spec/helpers/format_helper_spec.rb @@ -16,5 +16,18 @@ describe FormatHelper, type: :helper do it 'should return HTML for header markdown' do expect(markdown('# this is my header')).to eq "

this is my header

\n" end + + it 'escapes input HTML' do + expect(markdown('*a*')).to eq "

<em>a</em>

\n" + end + + it 'removes unallowed elements' do + expect(markdown('**', false)).to eq "

a

\n" + end + + it 'sets nofollow on links' do + expect(markdown('[a](https://example.com/)')) + .to eq "

a

\n" + end end end