Skip to content

Commit

Permalink
Use cssText instead of innerHTML to set theme styles.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcenizal committed Dec 15, 2017
1 parent a3ce294 commit 8c43cf4
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/ui/public/theme/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@ export function registerTheme(theme, styles) {
export function applyTheme(newTheme) {
currentTheme = newTheme;

// NOTE: The use of innerHTML opens up to XSS attacks, so we can't support user-generated themes
// as long as this implementation is in use. Ideally we would use the webpack style-loader/useable
// to activate and deactivate themes, but that causes the optimize step to fail.
document.getElementById('themeCss').innerHTML = themes[currentTheme];
const styleNode = document.getElementById('themeCss');

if (styleNode) {
const css = themes[currentTheme];

if (styleNode.styleSheet){
styleNode.styleSheet.cssText = css;
} else {
styleNode.appendChild(document.createTextNode(css));

}
}
}

export function getCurrentTheme() {
Expand Down

0 comments on commit 8c43cf4

Please sign in to comment.