Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tab nabbing vulnerability in formatted links #2674

Merged
merged 1 commit into from
Sep 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is noreferrer required? If I'm correct this was a workaround for FF, which was fixed in FF 52. This will cause issues with analytics reporting where traffic came from

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm 🤔 I think it would be best as a config option to set that

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would using a property such as Link.REL = "noopener"; be efficient?

Copy link
Contributor Author

@d4l-w4r d4l-w4r Jul 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to caniuse, the rel=noopener attribute is not supported by IE11, with rel=noreferrer at least being supported in Win 10 creators update versions of IE11. That's why I picked both attributes here.

This will cause issues with analytics reporting where traffic came from

Personally I would consider this a feature. But I could understand if you didn't want to make this decision as part of your library.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah my apologies, I should have checked IE support! This is good to go then. Thanks 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome :)
Please note though, that for a release that fixes the complete vulnerability, this commit as well as #2439 have to be included.

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