Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
} from './sanitation';
import {dev, user} from './log';
import {isAmp4Email} from './format';
import {removeElement} from './dom';
import {rewriteAttributeValue} from './url-rewrite';
import {startsWith} from './string';
import purify from 'dompurify/dist/purify.es';
/**
* @typedef {{addHook: !Function, removeAllHooks: !Function, sanitize: !Function}}
*/
export let DomPurifyDef;
// TODO(choumx): Convert this into a class to avoid import side effects.
/** @private @const {!DomPurifyDef} */
const DomPurify = purify(self);
/** @private @const {string} */
const TAG = 'purifier';
/**
* Tags that are only whitelisted for specific values of given attributes.
* @private @const {!Object}>}
*/
const WHITELISTED_TAGS_BY_ATTRS = {
'script': {
'attribute': 'type',
'values': ['application/json', 'application/ld+json'],
},
};
const PURIFY_PROFILES = /** @type {!DomPurifyConfig} */ ({
export function createPurifier(doc, opt_config) {
const domPurify = purify(self);
const config = Object.assign(opt_config || {}, standardPurifyConfig());
domPurify.setConfig(config);
addPurifyHooks(domPurify, doc);
return domPurify;
}