Skip to content

Commit

Permalink
Fix tab nabbing vulnerability in formatted links
Browse files Browse the repository at this point in the history
- Add attribute rel="noopener noreferrer"
  to <a> tags created by formats/link.js
- Make unit tests for links expect rel
  attribute
  • Loading branch information
d4l-w4r committed Jul 6, 2019
1 parent f32aa5f commit b2f7b58
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions formats/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Link extends Inline {
static create(value) {
const node = super.create(value);
node.setAttribute('href', this.sanitize(value));
node.setAttribute('rel', 'noopener noreferrer');
node.setAttribute('target', '_blank');
return node;
}
Expand Down
10 changes: 5 additions & 5 deletions test/unit/formats/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Link', function() {
.insert('3\n'),
);
expect(editor.scroll.domNode).toEqualHTML(
'<p>0<a href="https://quilljs.com" target="_blank">12</a>3</p>',
'<p>0<a href="https://quilljs.com" target="_blank" rel="noopener noreferrer">12</a>3</p>',
);
});

Expand All @@ -38,14 +38,14 @@ describe('Link', function() {
.insert('3\n'),
);
expect(editor.scroll.domNode).toEqualHTML(
'<p>0<a href="about:blank" target="_blank">12</a>3</p>',
'<p>0<a href="about:blank" target="_blank" rel="noopener noreferrer">12</a>3</p>',
);
});

it('change', function() {
const editor = this.initialize(
Editor,
'<p>0<a href="https://github.com" target="_blank">12</a>3</p>',
'<p>0<a href="https://github.com" target="_blank" rel="noopener noreferrer">12</a>3</p>',
);
editor.formatText(1, 2, { link: 'https://quilljs.com' });
expect(editor.getDelta()).toEqual(
Expand All @@ -55,14 +55,14 @@ describe('Link', function() {
.insert('3\n'),
);
expect(editor.scroll.domNode).toEqualHTML(
'<p>0<a href="https://quilljs.com" target="_blank">12</a>3</p>',
'<p>0<a href="https://quilljs.com" target="_blank" rel="noopener noreferrer">12</a>3</p>',
);
});

it('remove', function() {
const editor = this.initialize(
Editor,
'<p>0<a class="ql-size-large" href="https://quilljs.com" target="_blank">12</a>3</p>',
'<p>0<a class="ql-size-large" href="https://quilljs.com" target="_blank" rel="noopener noreferrer">12</a>3</p>',
);
editor.formatText(1, 2, { link: false });
const delta = new Delta()
Expand Down

0 comments on commit b2f7b58

Please sign in to comment.