Skip to content
Draft
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
3 changes: 2 additions & 1 deletion extension/js/common/platform/xss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class Xss {
private static ADD_ATTR = ['email', 'page', 'addurltext', 'longid', 'index', 'target', 'fingerprint', 'cryptup-data'];
private static FORBID_ATTR = ['background'];
private static HREF_REGEX_CACHE: RegExp | undefined;
private static FORBID_CSS_STYLE = /z-index:[^;]+;|position:[^;]+;|background[^;]+;/g;
private static FORBID_CSS_STYLE = /z-index:[^;]+(?=;|$)|position:[^;]+(?=;|$)|background[^;]+(?=;|$)/gi;
private static EMOJI_REGEX = /(?![*#0-9]+)[\p{Emoji}\p{Emoji_Modifier}\p{Emoji_Component}\p{Emoji_Modifier_Base}\p{Emoji_Presentation}]/gu;

public static sanitizeRender = (selector: string | HTMLElement | JQuery, dirtyHtml: string) => {
Expand Down Expand Up @@ -118,6 +118,7 @@ export class Xss {
const style = node.getAttribute('style')?.toLowerCase();
if (style && (style.includes('url(') || style.includes('@import'))) {
node.removeAttribute('style'); // don't want any leaks through css url()
return; // stop processing: do not re-add any part of this style attribute
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

if return will be executed here, then all next checks will be skipped?

so if style property includes some URL, then other checks for node.tagName === 'IMG' and node.tagName === 'A' won't be executed?
for example, <img src="https://example.com/tracker.png" style="background-image: url(https://example.com/bg.png)"> will return <img src="https://example.com/tracker.png"> - style property removed, but remote image is loaded

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, but I realize I should formulate even better logic to fix this rather than what's current. BRB.

}
// strip css styles that could use to overlap with the extension UI
if (style && Xss.FORBID_CSS_STYLE.test(style)) {
Expand Down
Loading