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:
Andrew Kvalheim 2023-03-03 16:51:01 -08:00
parent c54a8a1238
commit 80d7ac545c
2 changed files with 6 additions and 1 deletions

View file

@ -24,5 +24,10 @@ describe FormatHelper, type: :helper do
it 'removes unallowed elements' do
expect(markdown('<em>*<style>a</style>*</em>', false)).to eq "<p><em><em>a</em></em></p>\n"
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