Skip to content

Commit

Permalink
Set the noreferrer attribute to links and images
Browse files Browse the repository at this point in the history
An alternative fix to element-hq/element-web#6147 which for some reason
the PR element-hq/element-web#6155 is not yet merged.

The key difference is that the riot-web PR element-hq/element-web#6155
uses HTML meta header for noreferrer, while this one adds the
rel-attribute to include the noreferrer keyword in both user-created
links as well as links converted from incoming events.

I guess it's up to the maintainers then to pick and choose, but please
do ;).
  • Loading branch information
eras committed Oct 20, 2019
1 parent 4494e3b commit abd24a9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/HtmlUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ const transformTags = { // custom to matrix
}
}
attribs.rel = 'noopener'; // https://mathiasbynens.github.io/rel-noopener/
attribs.rel += ' noreferrer';
return { tagName, attribs };
},
'img': function(tagName, attribs) {
Expand All @@ -181,6 +182,7 @@ const transformTags = { // custom to matrix
attribs.width || 800,
attribs.height || 600,
);
attribs.rel = 'noreferrer';
return { tagName, attribs };
},
'code': function(tagName, attribs) {
Expand Down
2 changes: 1 addition & 1 deletion src/linkify-matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ matrixLinkify.options = {
},

linkAttributes: {
rel: 'noopener',
rel: 'noopener noreferrer',
},

target: function(href, type) {
Expand Down

0 comments on commit abd24a9

Please sign in to comment.