mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
Set nofollow on links in Markdown content
To disincentivize spamdexing, links in user-generated content should be disavowed by annotation with `rel="nofollow"` attributes: - https://en.wikipedia.org/wiki/Nofollow Automated spam has already targeted OSEM in the wild: - https://github.com/SeaGL/organization/issues/274 Ideally link annotation would be performed during Markdown rendering or a single sanitization pass, but this is currently an unresolved issue: - https://github.com/vmg/redcarpet/issues/720
This commit is contained in:
parent
c54a8a1238
commit
80d7ac545c
2 changed files with 6 additions and 1 deletions
|
|
@ -202,7 +202,7 @@ module FormatHelper
|
||||||
safe_links_only: true
|
safe_links_only: true
|
||||||
}
|
}
|
||||||
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(render_options), markdown_options)
|
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
|
end
|
||||||
|
|
||||||
def markdown_hint(text='')
|
def markdown_hint(text='')
|
||||||
|
|
|
||||||
|
|
@ -24,5 +24,10 @@ describe FormatHelper, type: :helper do
|
||||||
it 'removes unallowed elements' do
|
it 'removes unallowed elements' do
|
||||||
expect(markdown('<em>*<style>a</style>*</em>', false)).to eq "<p><em><em>a</em></em></p>\n"
|
expect(markdown('<em>*<style>a</style>*</em>', false)).to eq "<p><em><em>a</em></em></p>\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'sets nofollow on links' do
|
||||||
|
expect(markdown('[a](https://example.com/)'))
|
||||||
|
.to eq "<p><a href=\"https://example.com/\" rel=\"nofollow\">a</a></p>\n"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue