Skip to content

Commit c561c48

Browse files
force links to always open in new tab
1 parent 521705e commit c561c48

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

server/hooks/xss.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ const _ = require('lodash');
33

44
function clean (dirty) {
55
dirty = sanitizeHtml(dirty, {
6-
allowedTags: ['iframe', 'img', 'p', 'br', 'b', 'i', 'em', 'strong', 'a', 'pre', 'ul', 'li', 'ol'],
6+
allowedTags: ['iframe', 'img', 'p', 'br', 'b', 'i', 'em', 'strong', 'a', 'pre', 'ul', 'li', 'ol', 'span'],
77
allowedAttributes: {
8-
a: ['href', 'data-*'],
8+
a: ['href', 'target', 'data-*'],
99
img: [ 'src' ],
1010
iframe: ['src', 'class', 'frameborder', 'allowfullscreen']
1111
},
@@ -15,6 +15,15 @@ function clean (dirty) {
1515
},
1616
transformTags: {
1717
i: 'em',
18+
a: function (tagName, attribs) {
19+
return {
20+
tagName: 'a',
21+
attribs: {
22+
href: attribs.href,
23+
target: '_blank'
24+
}
25+
};
26+
},
1827
b: 'strong'
1928
// 'img': function (tagName, attribs) {
2029
// let src = attribs.src;

0 commit comments

Comments
 (0)