Skip to content

[fix #1467] Make sure target attribute is kept after DOMPurify sanitization #1468

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion src/core/render/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,10 @@ export function renderMixin(proto) {
},
tokens => {
html = this.compiler.compile(tokens);
html = this.isRemoteUrl ? DOMPurify.sanitize(html) : html;
// add "target" attribute to DOMPurify white list to handle external links
html = this.isRemoteUrl
? DOMPurify.sanitize(html, { ADD_ATTR: ['target'] })
Copy link
Member

Choose a reason for hiding this comment

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

so this change will skip sanitizing the attributes ?

Copy link
Author

Choose a reason for hiding this comment

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

No, this change will consider the target attribute as a valid one and will not remove it. But it does not prevent DOMPurify to sanitize the attribute content. For example, if the following code is present in the source

<a target="javascript:alert('XSS')" href="https://example.com">Test</a>

it will be changed to

<a href="https://example.com">Test</a>

because the value will be considered as unsafe.

Copy link
Member

Choose a reason for hiding this comment

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

cool, Can you add test(s) for this, Otherwise looks good to me

Copy link
Member

Choose a reason for hiding this comment

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

@Fab1en So if it sees target="_blank" then it will leave it in that case? Mind adding a small test case?

: html;
callback();
next();
}
Expand Down