Skip to content

Commit

Permalink
fix: circumvent style-src CSP in Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
tophf committed Dec 7, 2023
1 parent d5c482d commit 37ec011
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/injected/content/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const {
} = global;
const { createElementNS } = document;
const tdDecode = SafeTextDecoder[PROTO].decode;
const kTextContent = 'textContent';
// required in FF to circumvent CSP style-src https://bugzil.la/1706787
const setTextContent = describeProperty(Node[PROTO], kTextContent).set;
const regexpTest = RegExp[PROTO].test; // Deeply unsafe. TODO: remove.
const { createObjectURL } = URL;

Expand Down Expand Up @@ -39,10 +42,10 @@ export const onElement = (tag, cb, arg) => new SafePromise(resolve => {
export const makeElem = (tag, attrs) => {
const el = document::createElementNS('http://www.w3.org/1999/xhtml', tag);
if (attrs && isString(attrs)) {
el::append(attrs);
el::setTextContent(attrs);
} else if (attrs) {
objectKeys(attrs)::forEach(key => {
if (key === 'textContent') el::append(attrs[key]);
if (key === kTextContent) el::setTextContent(attrs[key]);
else el::setAttribute(key, attrs[key]);
});
}
Expand Down

0 comments on commit 37ec011

Please sign in to comment.