Skip to content

Commit

Permalink
refactor: favor directly modifying DOM attributes over setAttribute
Browse files Browse the repository at this point in the history
According to https://stackoverflow.com/a/57633533 setAttribute()
invokes the HTML parser, which can trigger a CSP violation.
This change refactors style element construction/manipulation to not leverage setAttribute().
  • Loading branch information
sherwinski committed Feb 18, 2021
1 parent 8d3738b commit 67666a3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/js/ZoomPane.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export default class ZoomPane {
removeClasses(this.el, this.closingClasses);
removeClasses(this.el, this.inlineClasses);

this.el.setAttribute("style", "");
this.el.style = "";

// The window could have been resized above or below `inline`
// limits since the ZoomPane was shown. Because of this, we
Expand Down
9 changes: 5 additions & 4 deletions src/js/injectBaseStylesheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ export default function injectBaseStylesheet() {

const styleEl = document.createElement("style");
styleEl.type = "text/css";
styleEl.classList.add("drift-base-styles");

styleEl.appendChild(document.createTextNode(RULES));
styleEl.classList = "drift-base-styles";

styleEl.textContent = RULES;
const head = document.head;
head.insertBefore(styleEl, head.firstChild);

const allHeadElements = head.getElementsByTagName("*");
allHeadElements.innerHTML = styleEl + allHeadElements.innerHTML;
}

0 comments on commit 67666a3

Please sign in to comment.