Skip to content

Commit 592765e

Browse files
committed
Remove base64 encoded binaries in <style>
It turns out that there are a lot of exensions in the world, and sometimes those extensions modify the DOM of the page (ours included). Generally we don't have a problem with this, but if an extension injects a large base64-encoded binary into the mix, then we run into problems. This is mostly because the request size very quickly can be bloated beyond the max. This change targets one particular place where this happens the most, in the <style> tag where someone may inject a custom font into the page. When we detect this, we remove the style (from our copy of the DOM) before sending it up.
1 parent 63ce6b2 commit 592765e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/scripts/domParsers/domUtils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,17 @@ export class DomUtils {
195195
return sanitizedHtml;
196196
}
197197

198+
/**
199+
* Many extensions inject their own stylings into the page, and generally that isn't a problem. But,
200+
* occasionally the styling includes a specific font, which can be very, very large. This method
201+
* removes any base64 encoded binaries defined in any <style> tags.
202+
*/
203+
public static removeStylesWithBase64EncodedBinaries(doc: Document): void {
204+
DomUtils.domReplacer(doc, "style", (node: HTMLElement) => {
205+
return node.innerHTML.indexOf("data:application") !== -1 ? document.createElement("style") : node;
206+
});
207+
}
208+
198209
public static removeElementsNotSupportedInOnml(doc: Document): void {
199210
// For elements that cannot be converted into something equivalent in ONML, we remove them ...
200211
DomUtils.domReplacer(doc, DomUtils.tagsNotSupportedInOnml.join());
@@ -332,6 +343,7 @@ export class DomUtils {
332343
}
333344

334345
public static removeUnwantedItems(doc: Document): void {
346+
DomUtils.removeStylesWithBase64EncodedBinaries(doc);
335347
DomUtils.removeClipperElements(doc);
336348
DomUtils.removeUnwantedElements(doc);
337349
DomUtils.removeUnwantedAttributes(doc);

0 commit comments

Comments
 (0)