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 authored and jhchen committed Sep 9, 2019
1 parent cc8526d commit ec5e3ce
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 @@ -6,6 +6,7 @@ class Link extends Inline {
let node = super.create(value);
value = this.sanitize(value);
node.setAttribute('href', 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 @@ -12,7 +12,7 @@ describe('Link', function() {
.insert('12', { link: 'https://quilljs.com' })
.insert('3\n')
);
expect(editor.scroll.domNode).toEqualHTML('<p>0<a href="https://quilljs.com" target="_blank">12</a>3</p>');
expect(editor.scroll.domNode).toEqualHTML('<p>0<a href="https://quilljs.com" target="_blank" rel="noopener noreferrer">12</a>3</p>');
});

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

it('change', function() {
let editor = this.initialize(Editor, '<p>0<a href="https://github.com" target="_blank">12</a>3</p>');
let editor = this.initialize(Editor, '<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(new Delta()
.insert('0')
.insert('12', { link: 'https://quilljs.com' })
.insert('3\n')
);
expect(editor.scroll.domNode).toEqualHTML('<p>0<a href="https://quilljs.com" target="_blank">12</a>3</p>');
expect(editor.scroll.domNode).toEqualHTML('<p>0<a href="https://quilljs.com" target="_blank" rel="noopener noreferrer">12</a>3</p>');
});

it('remove', function() {
let editor = this.initialize(Editor, '<p>0<a class="ql-size-large" href="https://quilljs.com" target="_blank">12</a>3</p>');
let editor = this.initialize(Editor, '<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 });
let delta = new Delta().insert('0').insert('12', { size: 'large' }).insert('3\n');
expect(editor.getDelta()).toEqual(delta);
Expand Down

0 comments on commit ec5e3ce

Please sign in to comment.